{"record":{"id":"14f2e5f65db13033","repo":"n8n-io/n8n","slug":"you-must-provide-selection-conditions-in-order-to","errorCode":null,"errorMessage":"You must provide selection conditions in order to find a single row.","messagePattern":"You must provide selection conditions in order to find a single row\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/entity-manager/EntityManager.ts","lineNumber":1060,"sourceCode":"\n\t/**\n\t * Finds first entity by a given find options.\n\t * If entity was not found in the database - returns null.\n\t */\n\tasync findOne<Entity extends ObjectLiteral>(\n\t\tentityClass: EntityTarget<Entity>,\n\t\toptions: FindOneOptions<Entity>,\n\t): Promise<Entity | null> {\n\t\tconst metadata = this.connection.getMetadata(entityClass);\n\n\t\t// prepare alias for built query\n\t\tlet alias: string = metadata.name;\n\t\tif (options && options.join) {\n\t\t\talias = options.join.alias;\n\t\t}\n\n\t\tif (!options.where) {\n\t\t\tthrow new Error(`You must provide selection conditions in order to find a single row.`);\n\t\t}\n\n\t\t// create query builder and apply find options\n\t\treturn this.createQueryBuilder<Entity>(entityClass, alias)\n\t\t\t.setFindOptions({\n\t\t\t\t...options,\n\t\t\t\ttake: 1,\n\t\t\t})\n\t\t\t.getOne();\n\t}\n\n\t/**\n\t * Finds first entity that matches given where condition.\n\t * If entity was not found in the database - returns null.\n\t */\n\tasync findOneBy<Entity extends ObjectLiteral>(\n\t\tentityClass: EntityTarget<Entity>,\n\t\twhere: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],","sourceCodeStart":1042,"sourceCodeEnd":1078,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/entity-manager/EntityManager.ts#L1042-L1078","documentation":"EntityManager.findOne (the oneWithOptions variant at EntityManager.ts:1060) requires a non-empty `where` clause. When `options.where` is falsy (undefined/null/empty), TypeORM refuses to run what would be an arbitrary 'SELECT ... LIMIT 1' returning the first row. This is a deliberate guard against silent full-table scans masquerading as a targeted lookup.","triggerScenarios":"Calling `manager.findOne(Entity, { where: undefined })` or `manager.findOne(Entity, {})`; building options conditionally and ending up with an object that has no `where` key; spreading a partial options object that lost its where clause; passing `null` because the caller 'didn't have conditions'.","commonSituations":"Refactor that moves the where clause into a separate variable that's sometimes undefined; copy-pasting a find template and forgetting to fill in conditions; optional-filter code paths like `where: name ? { name } : {}`.","solutions":["Always pass a concrete `where` predicate: `manager.findOne(User, { where: { id: 1 } })`.","If the lookup is intentionally broad, use `find()` with an explicit limit instead of findOne.","When building options dynamically, default `where` to a sentinel (e.g. `{ id: undefined }`) or short-circuit the call entirely when there are no conditions.","Type the options parameter strictly (FindOneOptions<Entity>) so TS flags missing where."],"exampleFix":"// before - no where clause\nconst u = await manager.findOne(User, opts ?? {});\n\n// after - always supply a where predicate, or skip the call\nif (!opts?.where) throw new Error('findOne requires conditions');\nconst u = await manager.findOne(User, opts);","handlingStrategy":"validation","validationCode":"function hasWhere<Entity>(opts: FindOneOptions<Entity>): opts is FindOneOptions<Entity> & { where: NonNullable<FindOneOptions<Entity>['where']> } {\n  return !!opts && !!opts.where;\n}\nif (!hasWhere(options)) {\n  throw new Error('findOne requires options.where');\n}\nawait manager.findOne(Entity, options);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make 'where' required in your service-layer types wrapping findOne.","Skip the call when you have no conditions rather than passing {}.","Use find() with take:1 for arbitrary single-row lookups.","Add a lint rule banning `findOne(Entity, {})`."],"tags":["typeorm","find","api-misuse","query-safety"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}