Skip to content

fix: apply default throw behavior in normalizeWhereCriteria when options is not provided - #12579

Closed
samkessaram wants to merge 6 commits into
typeorm:masterfrom
samkessaram:fix/normalize-where-criteria-default-throw
Closed

samkessaram wants to merge 6 commits into
typeorm:masterfrom
samkessaram:fix/normalize-where-criteria-default-throw

Conversation

@samkessaram

Copy link
Copy Markdown
Contributor

Fixes #12578

OrmUtils.normalizeWhereCriteria() returns criteria unvalidated when invalidWhereValuesBehavior is not configured, because if (!options) return criteria short-circuits before the default-throw logic runs. This causes update() and delete() to silently accept undefined/null in where conditions while find() correctly throws.

Fix: Replace the early return with options ??= {} so the existing fallback (?? "throw") applies.

Tests: Added unit tests covering default-throw for undefined, null, nested objects, and explicit ignore.

…ons is not provided

When invalidWhereValuesBehavior is not configured on the DataSource, normalizeWhereCriteria
short-circuits and returns criteria without validation. This causes update() and delete() to
silently accept undefined/null values in where conditions, while find() correctly throws.

Replace the early return with an empty object fallback so the existing default logic runs.

Closes typeorm#12578

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@github-actions github-actions Bot added the linked-issue PR references an issue label Jun 12, 2026
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (5) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Array criteria wrongly ignored ✓ Resolved 🐞 Bug ≡ Correctness
Description
normalizeWhereCriteria() now defaults options to {null/undefined:"ignore"} for any non-plain-object
criteria, which includes ObjectLiteral[] arrays, so undefined/null in OR-criteria gets silently
dropped instead of default-throwing. If any OR element normalizes to {}, QueryBuilder turns that
element into a 1=1 branch, making the OR condition always true and effectively removing filtering
for update/delete/softDelete/restore.
Code

src/util/OrmUtils.ts[R665-673]

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
  }
  // multiple criteria are possible at the top level
Evidence
Arrays are not plain objects, so the new branch defaults them to ignore null/undefined, and the
array recursion passes that ignore behavior into each criterion. QueryBuilder then converts an empty
object (no predicates) into 1=1; when this happens inside an OR list it makes the full WHERE
always true, which can lead to unfiltered updates/deletes. SelectQueryBuilder’s find-path shows the
expected default behavior is still throw even when where is an array.

src/util/OrmUtils.ts[556-563]
src/util/OrmUtils.ts[660-683]
src/query-builder/QueryBuilder.ts[1624-1694]
src/query-builder/QueryBuilder.ts[1483-1529]
src/query-builder/QueryBuilder.ts[1078-1096]
src/entity-manager/EntityManager.ts[852-887]
src/query-builder/SelectQueryBuilder.ts[4267-4282]
src/query-builder/SelectQueryBuilder.ts[4303-4314]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` currently applies the “entity instance default ignore” behavior to *any* non-plain object criteria. Arrays (`ObjectLiteral[]`) are non-plain objects, so top-level OR criteria arrays will default to `{ null: "ignore", undefined: "ignore" }` when no options are provided. This contradicts the intended default-throw behavior and can normalize an OR branch to `{}`, which QueryBuilder interprets as `1=1`, making the full OR condition always true.
## Issue Context
- Arrays are a supported `.where()` input (OR semantics).
- `QueryBuilder` treats empty predicate lists as `1=1`, and OR-ing with `1=1` makes the full condition match all rows.
## Fix Focus Areas
- src/util/OrmUtils.ts[660-683]
### Suggested change
Update the defaulting logic to *not* treat arrays as entity instances. For example:
- Handle the `Array.isArray(criteria)` case before the `isPlainObject`/entity-instance split, and default `options ??= {}` for arrays.
- Alternatively: `if (Array.isArray(criteria) || OrmUtils.isPlainObject(criteria)) options ??= {}; else options ??= { null: "ignore", undefined: "ignore" }`.
(Optionally) consider filtering out empty normalized OR elements and/or throwing if an OR list becomes empty after normalization, to avoid producing an always-true predicate.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Empty normalized entity criteria 🐞 Bug ☼ Reliability
Description
For non-plain-object criteria (e.g. entity instances), normalizeWhereCriteria() now defaults to
ignoring null/undefined and can normalize such criteria into an empty plain object. EntityManager’s
empty-criteria guard doesn’t apply to non-plain objects pre-normalization, so update/delete can
proceed with an empty normalized WHERE and run without any filtering.
Code

src/util/OrmUtils.ts[R667-670]

+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
Evidence
The new default-ignore branch applies specifically to non-plain objects and can drop all keys into
an empty {} result. EntityManager checks emptiness only on the original criteria and only for
plain objects, so a non-plain object with only nullish values can slip through; QueryBuilder then
treats empty predicates as 1=1 and omits them, resulting in no WHERE clause.

src/util/OrmUtils.ts[660-725]
src/util/OrmUtils.ts[387-395]
src/entity-manager/EntityManager.ts[852-887]
src/query-builder/QueryBuilder.ts[1078-1087]
src/query-builder/QueryBuilder.ts[865-925]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`normalizeWhereCriteria()` now defaults entity instances to `{ null: "ignore", undefined: "ignore" }` when options are not provided. If all enumerable properties are null/undefined (or become ignored), the function returns `{}`. In `EntityManager.update/delete/softDelete/restore`, the pre-check uses `isCriteriaNullOrEmpty(criteria)` *before* normalization; entity instances are not considered “plain objects” and bypass the empty-object check, so the operation can proceed and execute with an effectively unfiltered WHERE.
## Issue Context
- `isCriteriaNullOrEmpty()` only treats arrays and **plain** objects with zero keys as empty.
- QueryBuilder converts an empty predicate list to `1=1`, and `createWhereExpression()` omits `1=1`, producing no WHERE clause.
## Fix Focus Areas
- src/util/OrmUtils.ts[660-725]
### Suggested change
Add a safety guard so that after normalization, criteria cannot become empty for write operations:
- In `EntityManager.update/delete/softDelete/restore`, after `const normalizedCriteria = OrmUtils.normalizeWhereCriteria(...)`, re-check emptiness on `normalizedCriteria` (and for arrays, ensure no element is empty / no always-true OR branch), and throw the same “Empty criteria(s)…” error.
OR (if you want to contain the logic within normalization):
- When criteria is a non-plain object and options are defaulted to ignore, if the top-level normalized result has no keys, throw a `TypeORMError` indicating the criteria became empty after ignoring null/undefined (to prevent unfiltered writes).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Return type mismatch ✓ Resolved 🐞 Bug ≡ Correctness
Description
OrmUtils.normalizeWhereCriteria is declared to return ObjectLiteral, but it still returns
ObjectLiteral[] when the top-level criteria is an array. This will either fail TypeScript
compilation or mis-type callers (e.g. normalizedCriteria), despite QueryBuilder explicitly
supporting ObjectLiteral[] for .where().
Code

src/util/OrmUtils.ts[R664-668]

+    ): ObjectLiteral {
+        options ??= {}
// multiple criteria are possible at the top level
if (!path && Array.isArray(criteria)) {
Evidence
The function’s signature promises a single ObjectLiteral, but the top-level array branch returns
criteria.map(...) (an array). Separately, QueryBuilder’s where() overloads accept both
ObjectLiteral and ObjectLiteral[], confirming that the array return shape is valid and should be
reflected in the typing.

src/util/OrmUtils.ts[660-677]
src/query-builder/WhereExpressionBuilder.ts[14-39]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` now declares `): ObjectLiteral` but still returns an array (`criteria.map(...)`) when `criteria` is an array at the top level (`!path && Array.isArray(criteria)`). This is an internal contract violation and is likely a TypeScript build error.
### Issue Context
QueryBuilder supports `where(ObjectLiteral[])`, so `normalizeWhereCriteria` must preserve the array shape when input criteria is an array.
### Fix Focus Areas
- src/util/OrmUtils.ts[660-677]
### Suggested fix
- Change the return type back to `ObjectLiteral | ObjectLiteral[]` (or implement overloads):
- `normalizeWhereCriteria(criteria: ObjectLiteral, ...): ObjectLiteral`
- `normalizeWhereCriteria(criteria: ObjectLiteral[], ...): ObjectLiteral[]`
- Ensure the `return criteria.map(...)` branch type-checks cleanly under the chosen signature.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

4. Entity arrays lose ignore 🐞 Bug ≡ Correctness ⭐ New
Description
In OrmUtils.normalizeWhereCriteria(), the top-level array (OR) branch sets options ??= {}, which
prevents the later entity-instance fallback { null/undefined: "ignore" } from applying to
non-plain objects inside the array. As a result, passing an OR-array of entity instances to
update()/delete()/softDelete()/restore() can now throw on nullable entity properties even
though passing a single entity instance would ignore them by default.
Code

src/util/OrmUtils.ts[R665-675]

+        // multiple criteria are possible at the top level (OR semantics)
        if (!path && Array.isArray(criteria)) {
+            options ??= {}
            return criteria.map(
                (criterion, index): ObjectLiteral =>
                    OrmUtils.normalizeWhereCriteria(
                        criterion,
                        options,
                        String(index),
-                    ),
+                    ) as ObjectLiteral,
            )
Evidence
The array branch eagerly initializes options to {}, and the recursive calls then skip the
entity-instance defaulting because options is already defined. EntityManager passes non-primitive
criteria objects/arrays through this function for update/delete/softDelete/restore before calling
.where(), so OR-arrays of entity instances will hit this behavior.

src/util/OrmUtils.ts[660-685]
src/entity-manager/EntityManager.ts[837-887]
src/entity-manager/EntityManager.ts[925-963]
src/entity-manager/EntityManager.ts[991-1029]
src/entity-manager/EntityManager.ts[1042-1080]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`normalizeWhereCriteria()` currently does `options ??= {}` in the top-level array (OR) branch. This makes `options` defined for the recursive calls, so those calls never apply the non-plain-object default (`{ null: "ignore", undefined: "ignore" }`) intended for entity instances.

### Issue Context
The function already decides defaults based on whether the current `criteria` is a plain object vs a class instance. The array branch should not override that per-element defaulting.

### Fix Focus Areas
- src/util/OrmUtils.ts[665-676]

### Suggested change
Remove `options ??= {}` from the array branch and pass `options` through unchanged to the recursive calls. Each element will then apply the correct defaulting (`{}` for plain objects; `{ null/undefined: "ignore" }` for entity instances) inside the recursive call.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Null criteria TypeError 🐞 Bug ☼ Reliability
Description
normalizeWhereCriteria can now reach Object.entries(criteria) when criteria is null/undefined (e.g.
JS/dynamic callers), throwing a raw TypeError instead of a TypeORMError. This creates an unhelpful
crash path that bypasses the function’s intended validation/error messaging.
Code

src/util/OrmUtils.ts[R678-688]

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
+        }
+
      const result: ObjectLiteral = {}
      for (const [key, value] of Object.entries(criteria)) {
          const propertyPath = path ? `${path}.${key}` : key
Evidence
isPlainObject explicitly returns false for null/undefined, and normalizeWhereCriteria does not
validate criteria before iterating with Object.entries, so null/undefined criteria will crash at
runtime with a TypeError.

src/util/OrmUtils.ts[556-563]
src/util/OrmUtils.ts[660-688]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` now calls `Object.entries(criteria)` after defaulting `options`, even when `criteria` is `null`/`undefined` (possible from JS or `any`-typed call sites). This throws a raw `TypeError` rather than a controlled `TypeORMError`.
### Issue Context
Previously, `if (!options) return criteria` could short-circuit out of this path when options were omitted. After the change, the function always proceeds into the normalization loop, so `Object.entries(null)` / `Object.entries(undefined)` can crash.
### Fix Focus Areas
- Add an explicit input guard at the start of `normalizeWhereCriteria`:
- if `criteria === null || criteria === undefined`, throw `TypeORMError` (or return a safe value if you intentionally want to treat it as empty criteria—be explicit).
- optionally also guard `typeof criteria !== 'object'` to avoid `Object.entries` on primitives.
- Ensure the error message is consistent with the existing invalidWhereValuesBehavior messaging.
- src/util/OrmUtils.ts[660-726]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Circular criteria recursion 🐞 Bug ☼ Reliability
Description
normalizeWhereCriteria recursively descends into nested plain objects without cycle detection. With
the removed early return when options is omitted, cyclic criteria objects can now cause infinite
recursion/stack overflow.
Code

src/util/OrmUtils.ts[R665-685]

+        // multiple criteria are possible at the top level (OR semantics)
      if (!path && Array.isArray(criteria)) {
+            options ??= {}
          return criteria.map(
              (criterion, index): ObjectLiteral =>
                  OrmUtils.normalizeWhereCriteria(
                      criterion,
                      options,
                      String(index),
-                    ),
+                    ) as ObjectLiteral,
          )
      }
+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
+        }
+
Evidence
The PR makes the no-options call path proceed into normalization; the function then recurses into
nested plain objects without any memo/visited tracking, which is sufficient to create an infinite
recursion on cyclic inputs.

src/util/OrmUtils.ts[660-685]
src/util/OrmUtils.ts[711-719]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` recursively normalizes nested plain objects but does not track visited objects. If the input criteria contains a cycle (e.g. `const c:any = {}; c.self = c;`), the function will recurse until stack overflow.
### Issue Context
This became easier to trigger because the function no longer short-circuits when `options` is omitted; it now proceeds into recursive normalization for plain objects.
### Fix Focus Areas
- Add a `visited` structure (prefer `WeakSet<object>` or `WeakMap<object, true>`) that is:
- initialized once at the top-level call
- passed through recursive calls
- checked before descending into a nested object
- On detecting a cycle, throw a `TypeORMError` explaining that circular where criteria are not supported.
- src/util/OrmUtils.ts[660-726]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (3)
7. Prototype key injection 🐞 Bug ⛨ Security
Description
normalizeWhereCriteria() copies arbitrary keys from criteria into a plain {} without filtering
__proto__/constructor/prototype, so a crafted where object can mutate the prototype of the
normalized criteria and introduce inherited enumerable keys. Downstream where-building uses
for...in iteration, so inherited keys can create incorrect predicates or trigger unexpected
errors.
Code

src/util/OrmUtils.ts[R664-671]

+    ): ObjectLiteral {
+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
    }
Evidence
The function constructs result as a normal object and assigns result[key] directly from
Object.entries(criteria), with no guard against __proto__/prototype keys; the PR change makes
this normalization path run by default (no early return). Downstream, SelectQueryBuilder iterates
where objects with for (const key in where), which includes inherited enumerable properties (i.e.,
those introduced via prototype mutation). The codebase already skips __proto__ in
OrmUtils.merge(), indicating this is a known hazard.

src/util/OrmUtils.ts[660-721]
src/query-builder/SelectQueryBuilder.ts[4284-4289]
src/util/OrmUtils.ts[631-642]
src/entity-manager/EntityManager.ts[873-881]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` builds a new plain object (`{}`) and assigns `result[key] = ...` for every entry in `criteria`. If `criteria` contains prototype-related keys like `__proto__`, this assignment can change the prototype of the returned object and introduce inherited enumerable properties.
Because query building code iterates where objects using `for...in`, inherited enumerable properties can be processed as if they were real where keys, producing incorrect SQL predicates or unexpected errors.
### Issue Context
There is already precedent in this codebase to guard against `__proto__` in object-walking utilities.
### Fix Focus Areas
- src/util/OrmUtils.ts[660-725]
- src/query-builder/SelectQueryBuilder.ts[4284-4290]
### Suggested fix
1. Prevent prototype mutation in `normalizeWhereCriteria` by either:
- Creating the accumulator with a null prototype:
- `const result = Object.create(null) as ObjectLiteral`
- And/or explicitly skipping dangerous keys:
- `if (key === "__proto__" || key === "constructor" || key === "prototype") continue`
2. Apply the same guard before any `result[key] = ...` assignment (including the nested-object branch).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Docs omit entity-instance default ignore ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
normalizeWhereCriteria() now defaults to ignoring null/undefined when passed an entity class
instance, but the docs state the default behavior is to throw for null/undefined in where
conditions. This can mislead users relying on documented default validation behavior.
Code

src/util/OrmUtils.ts[R665-670]

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
Evidence
The implementation adds a default that ignores null/undefined for non-plain-object (entity
instance) criteria, while the docs state the default behavior is to throw when null/undefined
values are encountered in where conditions.

Rule 2: Docs updated for user-facing changes
src/util/OrmUtils.ts[665-670]
docs/docs/data-source/5-null-and-undefined-handling.md[13-16]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` now applies a special default behavior for entity class instances (`options ??= { null: "ignore", undefined: "ignore" }`), but the documentation currently describes the default as throwing on `null`/`undefined` values in where conditions.
## Issue Context
This PR introduces/solidifies user-visible behavior (also covered by the new unit test `"ignores null and undefined on entity class instances"`). The docs at `docs/docs/data-source/5-null-and-undefined-handling.md` describe the default behavior as throwing, without noting the entity-instance exception.
## Fix Focus Areas
- src/util/OrmUtils.ts[665-670]
- docs/docs/data-source/5-null-and-undefined-handling.md[13-16]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


9. Issue fix lacks functional test 📘 Rule violation ☼ Reliability
Description
The PR adds coverage only in test/unit for an issue fix, but the checklist prefers functional
coverage for issue fixes. This may allow regressions in the high-level update()/delete() flows
the issue describes.
Code

test/unit/util/orm-utils.test.ts[R274-312]

+    describe("normalizeWhereCriteria", () => {
+        it("throws on undefined values when options is not provided", () => {
+            expect(() =>
+                OrmUtils.normalizeWhereCriteria({ name: undefined }),
+            ).to.throw(/Undefined value.*'name'/)
+        })
+
+        it("throws on null values when options is not provided", () => {
+            expect(() =>
+                OrmUtils.normalizeWhereCriteria({ email: null }),
+            ).to.throw(/Null value.*'email'/)
+        })
+
+        it("throws on undefined in nested objects when options is not provided", () => {
+            expect(() =>
+                OrmUtils.normalizeWhereCriteria({ user: { id: undefined } }),
+            ).to.throw(/Undefined value.*'user\.id'/)
+        })
+
+        it("ignores undefined when options.undefined is 'ignore'", () => {
+            const result = OrmUtils.normalizeWhereCriteria(
+                { name: "Alice", email: undefined },
+                { undefined: "ignore" },
+            )
+            expect(result).to.deep.equal({ name: "Alice" })
+        })
+
+        it("ignores null and undefined on entity class instances", () => {
+            class User {
+                id = 1
+                name = "Alice"
+                parentId: number | null = null
+                deletedAt: Date | undefined = undefined
+            }
+            const entity = new User()
+            const result = OrmUtils.normalizeWhereCriteria(entity)
+            expect(result).to.deep.equal({ id: 1, name: "Alice" })
+        })
+    })
Evidence
New tests for the issue are added under test/unit/... rather than the functional test suite, which
does not meet the checklist's stated preference for functional coverage of issue fixes.

Rule 3: Prefer functional tests over per-issue tests
test/unit/util/orm-utils.test.ts[274-312]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
This issue fix adds tests in the unit test suite, but the compliance checklist prefers issue fixes to be covered by functional tests.
## Issue Context
The PR description states the bug affects high-level operations like `update()` and `delete()` when `invalidWhereValuesBehavior` is not configured. Functional tests would better validate end-to-end behavior through repository/manager APIs.
## Fix Focus Areas
- test/unit/util/orm-utils.test.ts[274-312]
- test/functional/null-undefined-handling/*

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Previous review results

Review updated until commit 7eb1566

Results up to commit 6a75261


🐞 Bugs (4) 📘 Rule violations (2) 📜 Skill insights (0)


Action required
1. Array criteria wrongly ignored ✓ Resolved 🐞 Bug ≡ Correctness
Description
normalizeWhereCriteria() now defaults options to {null/undefined:"ignore"} for any non-plain-object
criteria, which includes ObjectLiteral[] arrays, so undefined/null in OR-criteria gets silently
dropped instead of default-throwing. If any OR element normalizes to {}, QueryBuilder turns that
element into a 1=1 branch, making the OR condition always true and effectively removing filtering
for update/delete/softDelete/restore.
Code

src/util/OrmUtils.ts[R665-673]

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
    }
    // multiple criteria are possible at the top level
Evidence
Arrays are not plain objects, so the new branch defaults them to ignore null/undefined, and the
array recursion passes that ignore behavior into each criterion. QueryBuilder then converts an empty
object (no predicates) into 1=1; when this happens inside an OR list it makes the full WHERE
always true, which can lead to unfiltered updates/deletes. SelectQueryBuilder’s find-path shows the
expected default behavior is still throw even when where is an array.

src/util/OrmUtils.ts[556-563]
src/util/OrmUtils.ts[660-683]
src/query-builder/QueryBuilder.ts[1624-1694]
src/query-builder/QueryBuilder.ts[1483-1529]
src/query-builder/QueryBuilder.ts[1078-1096]
src/entity-manager/EntityManager.ts[852-887]
src/query-builder/SelectQueryBuilder.ts[4267-4282]
src/query-builder/SelectQueryBuilder.ts[4303-4314]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` currently applies the “entity instance default ignore” behavior to *any* non-plain object criteria. Arrays (`ObjectLiteral[]`) are non-plain objects, so top-level OR criteria arrays will default to `{ null: "ignore", undefined: "ignore" }` when no options are provided. This contradicts the intended default-throw behavior and can normalize an OR branch to `{}`, which QueryBuilder interprets as `1=1`, making the full OR condition always true.
## Issue Context
- Arrays are a supported `.where()` input (OR semantics).
- `QueryBuilder` treats empty predicate lists as `1=1`, and OR-ing with `1=1` makes the full condition match all rows.
## Fix Focus Areas
- src/util/OrmUtils.ts[660-683]
### Suggested change
Update the defaulting logic to *not* treat arrays as entity instances. For example:
- Handle the `Array.isArray(criteria)` case before the `isPlainObject`/entity-instance split, and default `options ??= {}` for arrays.
- Alternatively: `if (Array.isArray(criteria) || OrmUtils.isPlainObject(criteria)) options ??= {}; else options ??= { null: "ignore", undefined: "ignore" }`.
(Optionally) consider filtering out empty normalized OR elements and/or throwing if an OR list becomes empty after normalization, to avoid producing an always-true predicate.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Empty normalized entity criteria 🐞 Bug ☼ Reliability
Description
For non-plain-object criteria (e.g. entity instances), normalizeWhereCriteria() now defaults to
ignoring null/undefined and can normalize such criteria into an empty plain object. EntityManager’s
empty-criteria guard doesn’t apply to non-plain objects pre-normalization, so update/delete can
proceed with an empty normalized WHERE and run without any filtering.
Code

src/util/OrmUtils.ts[R667-670]

+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
Evidence
The new default-ignore branch applies specifically to non-plain objects and can drop all keys into
an empty {} result. EntityManager checks emptiness only on the original criteria and only for
plain objects, so a non-plain object with only nullish values can slip through; QueryBuilder then
treats empty predicates as 1=1 and omits them, resulting in no WHERE clause.

src/util/OrmUtils.ts[660-725]
src/util/OrmUtils.ts[387-395]
src/entity-manager/EntityManager.ts[852-887]
src/query-builder/QueryBuilder.ts[1078-1087]
src/query-builder/QueryBuilder.ts[865-925]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`normalizeWhereCriteria()` now defaults entity instances to `{ null: "ignore", undefined: "ignore" }` when options are not provided. If all enumerable properties are null/undefined (or become ignored), the function returns `{}`. In `EntityManager.update/delete/softDelete/restore`, the pre-check uses `isCriteriaNullOrEmpty(criteria)` *before* normalization; entity instances are not considered “plain objects” and bypass the empty-object check, so the operation can proceed and execute with an effectively unfiltered WHERE.
## Issue Context
- `isCriteriaNullOrEmpty()` only treats arrays and **plain** objects with zero keys as empty.
- QueryBuilder converts an empty predicate list to `1=1`, and `createWhereExpression()` omits `1=1`, producing no WHERE clause.
## Fix Focus Areas
- src/util/OrmUtils.ts[660-725]
### Suggested change
Add a safety guard so that after normalization, criteria cannot become empty for write operations:
- In `EntityManager.update/delete/softDelete/restore`, after `const normalizedCriteria = OrmUtils.normalizeWhereCriteria(...)`, re-check emptiness on `normalizedCriteria` (and for arrays, ensure no element is empty / no always-true OR branch), and throw the same “Empty criteria(s)…” error.
OR (if you want to contain the logic within normalization):
- When criteria is a non-plain object and options are defaulted to ignore, if the top-level normalized result has no keys, throw a `TypeORMError` indicating the criteria became empty after ignoring null/undefined (to prevent unfiltered writes).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Return type mismatch ✓ Resolved 🐞 Bug ≡ Correctness
Description
OrmUtils.normalizeWhereCriteria is declared to return ObjectLiteral, but it still returns
ObjectLiteral[] when the top-level criteria is an array. This will either fail TypeScript
compilation or mis-type callers (e.g. normalizedCriteria), despite QueryBuilder explicitly
supporting ObjectLiteral[] for .where().
Code

src/util/OrmUtils.ts[R664-668]

+    ): ObjectLiteral {
+        options ??= {}
  // multiple criteria are possible at the top level
  if (!path && Array.isArray(criteria)) {
Evidence
The function’s signature promises a single ObjectLiteral, but the top-level array branch returns
criteria.map(...) (an array). Separately, QueryBuilder’s where() overloads accept both
ObjectLiteral and ObjectLiteral[], confirming that the array return shape is valid and should be
reflected in the typing.

src/util/OrmUtils.ts[660-677]
src/query-builder/WhereExpressionBuilder.ts[14-39]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` now declares `): ObjectLiteral` but still returns an array (`criteria.map(...)`) when `criteria` is an array at the top level (`!path && Array.isArray(criteria)`). This is an internal contract violation and is likely a TypeScript build error.
### Issue Context
QueryBuilder supports `where(ObjectLiteral[])`, so `normalizeWhereCriteria` must preserve the array shape when input criteria is an array.
### Fix Focus Areas
- src/util/OrmUtils.ts[660-677]
### Suggested fix
- Change the return type back to `ObjectLiteral | ObjectLiteral[]` (or implement overloads):
- `normalizeWhereCriteria(criteria: ObjectLiteral, ...): ObjectLiteral`
- `normalizeWhereCriteria(criteria: ObjectLiteral[], ...): ObjectLiteral[]`
- Ensure the `return criteria.map(...)` branch type-checks cleanly under the chosen signature.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
4. Null criteria TypeError 🐞 Bug ☼ Reliability ⭐ New
Description
normalizeWhereCriteria can now reach Object.entries(criteria) when criteria is null/undefined (e.g.
JS/dynamic callers), throwing a raw TypeError instead of a TypeORMError. This creates an unhelpful
crash path that bypasses the function’s intended validation/error messaging.
Code

src/util/OrmUtils.ts[R678-688]

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
+        }
+
        const result: ObjectLiteral = {}
        for (const [key, value] of Object.entries(criteria)) {
            const propertyPath = path ? `${path}.${key}` : key
Evidence
isPlainObject explicitly returns false for null/undefined, and normalizeWhereCriteria does not
validate criteria before iterating with Object.entries, so null/undefined criteria will crash at
runtime with a TypeError.

src/util/OrmUtils.ts[556-563]
src/util/OrmUtils.ts[660-688]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`OrmUtils.normalizeWhereCriteria()` now calls `Object.entries(criteria)` after defaulting `options`, even when `criteria` is `null`/`undefined` (possible from JS or `any`-typed call sites). This throws a raw `TypeError` rather than a controlled `TypeORMError`.

### Issue Context
Previously, `if (!options) return criteria` could short-circuit out of this path when options were omitted. After the change, the function always proceeds into the normalization loop, so `Object.entries(null)` / `Object.entries(undefined)` can crash.

### Fix Focus Areas
- Add an explicit input guard at the start of `normalizeWhereCriteria`:
 - if `criteria === null || criteria === undefined`, throw `TypeORMError` (or return a safe value if you intentionally want to treat it as empty criteria—be explicit).
 - optionally also guard `typeof criteria !== 'object'` to avoid `Object.entries` on primitives.
- Ensure the error message is consistent with the existing invalidWhereValuesBehavior messaging.

- src/util/OrmUtils.ts[660-726]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Circular criteria recursion 🐞 Bug ☼ Reliability ⭐ New
Description
normalizeWhereCriteria recursively descends into nested plain objects without cycle detection. With
the removed early return when options is omitted, cyclic criteria objects can now cause infinite
recursion/stack overflow.
Code

src/util/OrmUtils.ts[R665-685]

+        // multiple criteria are possible at the top level (OR semantics)
        if (!path && Array.isArray(criteria)) {
+            options ??= {}
            return criteria.map(
                (criterion, index): ObjectLiteral =>
                    OrmUtils.normalizeWhereCriteria(
                        criterion,
                        options,
                        String(index),
-                    ),
+                    ) as ObjectLiteral,
            )
        }

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
+        }
+
Evidence
The PR makes the no-options call path proceed into normalization; the function then recurses into
nested plain objects without any memo/visited tracking, which is sufficient to create an infinite
recursion on cyclic inputs.

src/util/OrmUtils.ts[660-685]
src/util/OrmUtils.ts[711-719]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`OrmUtils.normalizeWhereCriteria()` recursively normalizes nested plain objects but does not track visited objects. If the input criteria contains a cycle (e.g. `const c:any = {}; c.self = c;`), the function will recurse until stack overflow.

### Issue Context
This became easier to trigger because the function no longer short-circuits when `options` is omitted; it now proceeds into recursive normalization for plain objects.

### Fix Focus Areas
- Add a `visited` structure (prefer `WeakSet<object>` or `WeakMap<object, true>`) that is:
 - initialized once at the top-level call
 - passed through recursive calls
 - checked before descending into a nested object
- On detecting a cycle, throw a `TypeORMError` explaining that circular where criteria are not supported.

- src/util/OrmUtils.ts[660-726]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


6. Prototype key injection 🐞 Bug ⛨ Security
Description
normalizeWhereCriteria() copies arbitrary keys from criteria into a plain {} without filtering
__proto__/constructor/prototype, so a crafted where object can mutate the prototype of the
normalized criteria and introduce inherited enumerable keys. Downstream where-building uses
for...in iteration, so inherited keys can create incorrect predicates or trigger unexpected
errors.
Code

src/util/OrmUtils.ts[R664-671]

+    ): ObjectLiteral {
+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
      }
Evidence
The function constructs result as a normal object and assigns result[key] directly from
Object.entries(criteria), with no guard against __proto__/prototype keys; the PR change makes
this normalization path run by default (no early return). Downstream, SelectQueryBuilder iterates
where objects with for (const key in where), which includes inherited enumerable properties (i.e.,
those introduced via prototype mutation). The codebase already skips __proto__ in
OrmUtils.merge(), indicating this is a known hazard.

src/util/OrmUtils.ts[660-721]
src/query-builder/SelectQueryBuilder.ts[4284-4289]
src/util/OrmUtils.ts[631-642]
src/entity-manager/EntityManager.ts[873-881]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` builds a new plain object (`{}`) and assigns `result[key] = ...` for every entry in `criteria`. If `criteria` contains prototype-related keys like `__proto__`, this assignment can change the prototype of the returned object and introduce inherited enumerable properties.
Because query building code iterates where objects using `for...in`, inherited enumerable properties can be processed as if they were real where keys, producing incorrect SQL predicates or unexpected errors.
### Issue Context
There is already precedent in this codebase to guard against `__proto__` in object-walking utilities.
### Fix Focus Areas
- src/util/OrmUtils.ts[660-725]
- src/query-builder/SelectQueryBuilder.ts[4284-4290]
### Suggested fix
1. Prevent prototype mutation in `normalizeWhereCriteria` by either:
- Creating the accumulator with a null prototype:
  - `const result = Object.create(null) as ObjectLiteral`
- And/or explicitly skipping dangerous keys:
  - `if (key === "__proto__" || key === "constructor" || key === "prototype") continue`
2. Apply the same guard before any `result[key] = ...` assignment (including the nested-object branch).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (2)
7. Docs omit entity-instance default ignore 📘 Rule violation ⚙ Maintainability
Description
normalizeWhereCriteria() now defaults to ignoring null/undefined when passed an entity class
instance, but the docs state the default behavior is to throw for null/undefined in where
conditions. This can mislead users relying on documented default validation behavior.
Code

src/util/OrmUtils.ts[R665-670]

+        if (OrmUtils.isPlainObject(criteria)) {
+            options ??= {}
+        } else {
+            // Entity class instances may carry nullable columns (e.g. foreign keys)
+            // that are not intended as filter conditions — default to ignoring them.
+            options ??= { null: "ignore", undefined: "ignore" }
Evidence
The implementation adds a default that ignores null/undefined for non-plain-object (entity
instance) criteria, while the docs state the default behavior is to throw when null/undefined
values are encountered in where conditions.

Rule 2: Docs updated for user-facing changes
src/util/OrmUtils.ts[665-670]
docs/docs/data-source/5-null-and-undefined-handling.md[13-16]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`OrmUtils.normalizeWhereCriteria()` now applies a special default behavior for entity class instances (`options ??= { null: "ignore", undefined: "ignore" }`), but the documentation currently describes the default as throwing on `null`/`undefined` values in where conditions.
## Issue Context
This PR introduces/solidifies user-visible behavior (also covered by the new unit test `"ignores null and undefined on entity class instances"`). The docs at `docs/docs/data-source/5-null-and-undefined-handling.md` describe the default behavior as throwing, without noting the entity-instance exception.
## Fix Focus Areas
- src/util/OrmUtils.ts[665-670]
- docs/docs/data-source/5-null-and-undefined-handling.md[13-16]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


8. Issue fix lacks functional test 📘 Rule violation ☼ Reliability
Description
The PR adds coverage only in test/unit for an issue fix, but the checklist prefers functional
coverage for issue fixes. This may allow regressions in the high-level update()/delete() flows
the issue describes.
Code

test/unit/util/orm-utils.test.ts[R274-312]

+    describe("normalizeWhereCriteria", () => {
+        it("throws on undefined values when options is not provided", () => {
+            expect(() =>
+                OrmUtils.normalizeWhereCriteria({ name: undefined }),
+            ).to.throw(/Undefined value.*'name'/)
+        })
+
+        it("throws on null values when options is not provided", () => {
+            expect(() =>
+                OrmUtils.normalizeWhereCriteria({ email: null }),
+            ).to.throw(/Null value.*'email'/)
+        })
+
+        it("throws on undefined in nested objects when options is not provided", () => {
+            expect(() =>
+                OrmUtils.normalizeWhereCriteria({ user: { id: undefined } }),
+            ).to.throw(/Undefined value.*'user\.id'/)
+        })
+
+        it("ignores undefined when options.undefined is 'ignore'", () => {
+            const result = OrmUtils.normalizeWhereCriteria(
+                { name: "Alice", email: undefined },
+                { undefined: "ignore" },
+            )
+            expect(result).to.deep.equal({ name: "Alice" })
+        })
+
+        it("ignores null and undefined on entity class instances", () => {
+            class User {
+                id = 1
+                name = "Alice"
+                parentId: number | null = null
+                deletedAt: Date | undefined = undefined
+            }
+            const entity = new User()
+            const result = OrmUtils.normalizeWhereCriteria(entity)
+            expect(result).to.deep.equal({ id: 1, name: "Alice" })
+        })
+    })
Evidence
New tests for the issue are added under test/unit/... rather than the functional test suite, which
does not meet the checklist's stated preference for functiona...

@alumni
alumni requested a review from naorpeled June 12, 2026 17:51
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
  • typeorm-sql-js-example

    npm i https://pkg.pr.new/typeorm@12579
    

commit: cdb5b7c

@gioboa gioboa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @samkessaram LGTM 👍

@samkessaram

Copy link
Copy Markdown
Contributor Author

Cool, looks like it is affecting other tests so I'll check that out.

…malizeWhereCriteria

When an entity instance (e.g. from repository.save()) is passed to softDelete/delete/update,
nullable columns like foreign keys are not intended as filter conditions. Use isPlainObject to
distinguish entity instances from plain FindOptionsWhere objects and default to ignoring
null/undefined on the former while preserving strict throw behavior for the latter.

Also fix typo: indempotence → idempotence in test description.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comment thread src/util/OrmUtils.ts Outdated
Comment on lines +665 to +670
if (OrmUtils.isPlainObject(criteria)) {
options ??= {}
} else {
// Entity class instances may carry nullable columns (e.g. foreign keys)
// that are not intended as filter conditions — default to ignoring them.
options ??= { null: "ignore", undefined: "ignore" }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like some extra attention here, as this check wasn't in before. The commit message, for reference:

When an entity instance (e.g. from repository.save()) is passed to softDelete/delete/update,
nullable columns like foreign keys are not intended as filter conditions. Use isPlainObject to
distinguish entity instances from plain FindOptionsWhere objects and default to ignoring
null/undefined on the former while preserving strict throw behavior for the latter.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one, can you please share some examples that emphasize using ignore and not throw on both? 🙏

Thanks in advance

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I'm thinking:

Plain objects ({ id: 1, name: undefined }): more likely a bug I think, either some value not being returned when expected or just human error. Default: throw.

Entity class instances: these carry all columns including nullable foreign keys (parentId: null, deletedAt: undefined). When passed to softDelete(entity), only the non-null fields should form the WHERE clause. Default: ignore.

// Plain object --> throw 
const name = await fetchUserName(id) // returns null unexpectedly
repo.delete({ name }) // throws — prevents unfiltered delete

// Entity instance --> ignore
class Post {
  id = 1
  authorId: number | null = null  // nullable FK
}
repo.softDelete(new Post()) // Not plain object, drop authorId, filter is just WHERE id = 1

We use isPlainObject() to distinguish these cases — entity instances created with new have a class prototype and aren't plain objects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alumni wdyt?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking that right now the logic is a bit convoluted.

The isPlainObject check should be done before iterating through the keys (we should have an early return if it's not a plain object) and the options should determined at the beginning of the functions in a single way (and not have multiple fallback values).

Also, I'm thinking that maybe we should have two PRs, one for the plain object check which we can backport to 0.3 and one for the default value which we should not.

@naorpeled naorpeled Jun 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, @samkessaram would you like to take this ? Or would you rather me to take it?🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @naorpeled, yeah I wouldn't mind if you took on that. Sorry—some things have come up on my side. I can check back in after I get some stuff sorted and am happy to help wherever needed.

@samkessaram

Copy link
Copy Markdown
Contributor Author

@naorpeled

Copy link
Copy Markdown
Member

Hey @samkessaram,
Can you please address Qodo's feedback? 🙏

Array criteria (OR semantics) were falling into the entity-instance
branch and defaulting to ignore null/undefined instead of throwing.
Move array handling before the plain-object/entity split and restore
the correct return type.
@belljinwo-jpg

Copy link
Copy Markdown

Since #12595 was closed as a duplicate of this PR, here are the tested pieces from that implementation that may help finish the canonical fix:

  • functional write-path coverage for EntityManager.update() and delete() under default null/undefined behavior;
  • a null-prototype normalization accumulator plus regression coverage for JSON-parsed __proto__ criteria;
  • entity-instance passthrough only when the option is omitted, while explicitly configured behavior still validates the instance;
  • focused functional suite: 24 passing; complete SQL.js suite: 2,965 passing, 179 pending, 0 failing.

The implementation and commits remain available in #12595. I’m happy to split or rebase the relevant tests/fixes if that is preferable to cherry-picking them.

@naorpeled naorpeled closed this Jun 26, 2026
naorpeled added a commit that referenced this pull request Jul 10, 2026
…he write path

When invalidWhereValuesBehavior was unset, OrmUtils.normalizeWhereCriteria
short-circuited via `if (!options) return criteria`, so update/delete/
softDelete/restore silently ran with null/undefined in plain-object criteria
instead of throwing — even though the read/find path already throws by default.
Default the options (`options ??= {}`) so the write path matches: a
null/undefined value in a plain-object (or array) criteria throws by default.
Entity instances, FindOperators, Date/Buffer and primitives still pass through
(the isPlainObject guard); configured ignore/sql-null are unchanged.

Closes #12578. Completes the approach from the closed #12579.

Co-authored-by: samkessaram <[email protected]>
naorpeled added a commit that referenced this pull request Jul 10, 2026
…he write path

When invalidWhereValuesBehavior was unset, OrmUtils.normalizeWhereCriteria
short-circuited via `if (!options) return criteria`, so update/delete/
softDelete/restore silently ran with null/undefined in plain-object criteria
instead of throwing — even though the read/find path already throws by default.
Default the options (`options ??= {}`) so the write path matches: a
null/undefined value in a plain-object (or array) criteria throws by default.
Entity instances, FindOperators, Date/Buffer and primitives still pass through
(the isPlainObject guard); configured ignore/sql-null are unchanged.

Closes #12578. Completes the approach from the closed #12579.

Co-authored-by: samkessaram <[email protected]>
naorpeled added a commit that referenced this pull request Jul 10, 2026
…he write path

When invalidWhereValuesBehavior was unset, OrmUtils.normalizeWhereCriteria
short-circuited via `if (!options) return criteria`, so update/delete/
softDelete/restore silently ran with null/undefined in plain-object criteria
instead of throwing — even though the read/find path already throws by default.
Default the options (`options ??= {}`) so the write path matches: a
null/undefined value in a plain-object (or array) criteria throws by default.
Entity instances, FindOperators, Date/Buffer and primitives still pass through
(the isPlainObject guard); configured ignore/sql-null are unchanged.

Closes #12578. Completes the approach from the closed #12579.

Co-authored-by: samkessaram <[email protected]>
naorpeled added a commit that referenced this pull request Jul 10, 2026
…he write path

When invalidWhereValuesBehavior was unset, OrmUtils.normalizeWhereCriteria
short-circuited via `if (!options) return criteria`, so update/delete/
softDelete/restore silently ran with null/undefined in plain-object criteria
instead of throwing — even though the read/find path already throws by default.
Default the options (`options ??= {}`) so the write path matches: a
null/undefined value in a plain-object (or array) criteria throws by default.
Entity instances, FindOperators, Date/Buffer and primitives still pass through
(the isPlainObject guard); configured ignore/sql-null are unchanged.

Closes #12578. Completes the approach from the closed #12579.

Co-authored-by: samkessaram <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linked-issue PR references an issue

Development

Successfully merging this pull request may close these issues.

OrmUtils.normalizeWhereCriteria() does not implement described default behaviour for invalidWhereValuesBehavior

5 participants