{"id":"6ba2a67663e9e174","repo":"typeorm/typeorm","slug":"undefined-value-encountered-in-property-alias","errorCode":null,"errorMessage":"Undefined value encountered in property '${alias}.${key}' of a where condition. Set 'invalidWhereValuesBehavior.undefined' to 'ignore' in connection options to skip properties with undefined values.","messagePattern":"Undefined value encountered in property '(.+?)\\.(.+?)' of a where condition\\. Set 'invalidWhereValuesBehavior\\.undefined' to 'ignore' in connection options to skip properties with undefined values\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/query-builder/SelectQueryBuilder.ts","lineNumber":4376,"sourceCode":"                    metadata.findColumnWithPropertyPathStrict(propertyPath)\n                const embed =\n                    metadata.findEmbeddedWithPropertyPath(propertyPath)\n                const relation =\n                    metadata.findRelationWithPropertyPath(propertyPath)\n\n                if (!embed && !column && !relation) {\n                    throw new EntityPropertyNotFoundError(\n                        propertyPath,\n                        metadata,\n                    )\n                }\n\n                if (parameterValue === undefined) {\n                    const undefinedBehavior =\n                        this.dataSource.options.invalidWhereValuesBehavior\n                            ?.undefined ?? \"throw\"\n                    if (undefinedBehavior === \"throw\") {\n                        throw new TypeORMError(\n                            `Undefined value encountered in property '${alias}.${key}' of a where condition. ` +\n                                `Set 'invalidWhereValuesBehavior.undefined' to 'ignore' in connection options to skip properties with undefined values.`,\n                        )\n                    }\n                    continue\n                }\n\n                if (parameterValue === null) {\n                    const nullBehavior =\n                        this.dataSource.options.invalidWhereValuesBehavior\n                            ?.null ?? \"throw\"\n                    if (nullBehavior === \"ignore\") {\n                        continue\n                    } else if (nullBehavior === \"throw\") {\n                        throw new TypeORMError(\n                            `Null value encountered in property '${alias}.${key}' of a where condition. ` +\n                                `To match with SQL NULL, the IsNull() operator must be used. ` +\n                                `Set 'invalidWhereValuesBehavior.null' to 'ignore' or 'sql-null' in connection options to skip or handle null values.`,","sourceCodeStart":4358,"sourceCodeEnd":4394,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/query-builder/SelectQueryBuilder.ts#L4358-L4394","documentation":"Thrown in buildWhere when a where value is strictly undefined and the connection option invalidWhereValuesBehavior.undefined is at its default 'throw'. TypeORM refuses to silently produce 'col = NULL' (which never matches) or skip the predicate; it makes the ambiguity explicit. Set the option to 'ignore' to drop such properties instead.","triggerScenarios":"Calling repo.find({ where: { email: maybeUndefined } }) where maybeUndefined is undefined at runtime; spreading an object that has optional keys not set; using a query-string value that was not provided. The default undefined behavior is 'throw'.","commonSituations":"Optional HTTP query params mapped directly into where; partial search forms; object spread that copies undefined; upgrading TypeORM to a version that introduced invalidWhereValuesBehavior (older versions silently included undefined).","solutions":["Strip undefined values from the where object before calling find (e.g. JSON.parse(JSON.stringify(where)) or a compact utility).","Set invalidWhereValuesBehavior: { undefined: 'ignore' } in DataSource options if dropping is the desired behavior.","Default optional inputs to a concrete value or use FindOperator (IsNull, IsNull, etc.) explicitly.","Use a typed where builder that omits undefined keys."],"exampleFix":"// before\nconst email = req.query.email // string | undefined\nrepo.find({ where: { email } })\n\n// after\nconst where: FindOptionsWhere<User> = {}\nif (typeof email === 'string') where.email = email\nrepo.find({ where })","handlingStrategy":"validation","validationCode":"function stripUndefined<T extends object>(obj: T): T {\n  return Object.fromEntries(Object.entries(obj).filter(([, v]) => v !== undefined)) as T\n}\nrepo.find({ where: stripUndefined(rawWhere) })","typeGuard":"function hasNoUndefined(obj: Record<string, unknown>): boolean {\n  return Object.values(obj).every(v => v !== undefined)\n}","tryCatchPattern":null,"preventionTips":["Build where objects conditionally: only set keys with concrete values.","Set invalidWhereValuesBehavior: { undefined: 'ignore' } if dropping undefined is intended.","Treat optional HTTP params as absent rather than undefined in the where map."],"tags":["find-options","where","undefined","input-validation","connection-options"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}