n8n-io/n8n · error · Error
You must provide selection conditions in order to find a sin
Error message
You must provide selection conditions in order to find a single row.
What it means
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.
Source
Thrown at packages/@n8n/typeorm/src/entity-manager/EntityManager.ts:1060
/**
* Finds first entity by a given find options.
* If entity was not found in the database - returns null.
*/
async findOne<Entity extends ObjectLiteral>(
entityClass: EntityTarget<Entity>,
options: FindOneOptions<Entity>,
): Promise<Entity | null> {
const metadata = this.connection.getMetadata(entityClass);
// prepare alias for built query
let alias: string = metadata.name;
if (options && options.join) {
alias = options.join.alias;
}
if (!options.where) {
throw new Error(`You must provide selection conditions in order to find a single row.`);
}
// create query builder and apply find options
return this.createQueryBuilder<Entity>(entityClass, alias)
.setFindOptions({
...options,
take: 1,
})
.getOne();
}
/**
* Finds first entity that matches given where condition.
* If entity was not found in the database - returns null.
*/
async findOneBy<Entity extends ObjectLiteral>(
entityClass: EntityTarget<Entity>,
where: FindOptionsWhere<Entity> | FindOptionsWhere<Entity>[],View on GitHub (pinned to 5ac6606e81)
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.
Example fix
// before - no where clause
const u = await manager.findOne(User, opts ?? {});
// after - always supply a where predicate, or skip the call
if (!opts?.where) throw new Error('findOne requires conditions');
const u = await manager.findOne(User, opts); Defensive patterns
Strategy: validation
Validate before calling
function hasWhere<Entity>(opts: FindOneOptions<Entity>): opts is FindOneOptions<Entity> & { where: NonNullable<FindOneOptions<Entity>['where']> } {
return !!opts && !!opts.where;
}
if (!hasWhere(options)) {
throw new Error('findOne requires options.where');
}
await manager.findOne(Entity, options); Prevention
- 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, {})`.
When it happens
Trigger: 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'.
Common situations: 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 } : {}`.
Related errors
- Transaction method requires callback in second parameter if
- Column "${columnName}" was not found in table "${metadata.na
- Column ${propertyPath} was not found in ${metadata.targetNam
- Value "${value}" is not a number.
- Custom entity repository ${repository.name} cannot inherit R
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/14f2e5f65db13033.
Report an issue: GitHub.