Repository navigation
fix(entity-manager): default invalidWhereValuesBehavior to throw on the write path - #12690
Conversation
commit: |
Code Review by Qodo
1. Object-valued criteria throws
|
ca58f18 to
88d8c49
Compare
…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]>
88d8c49 to
b4ea459
Compare
|
smith-xyz
left a comment
There was a problem hiding this comment.
lgtm!
one thing to maybe note is that increment/decrement might bypass this error? Not sure if that was pre-existing or needs adjusted here



Closes #12578.
Problem
invalidWhereValuesBehavior's documented default is throw, and the read/find path already honours it —SelectQueryBuilder.buildWhereresolves each sub-option with?? "throw". The write path did not:OrmUtils.normalizeWhereCriteriashort-circuited withif (!options) return criteriawhen the option was unset, soupdate/delete/softDelete/restorewith a plain-object criteria containingnull/undefinedran silently (col = NULL) instead of throwing. That's the bug reported in #12578 (repro: https://github.com/samkessaram/typeorm-undefined-where-bug).Change
Default the options inside
normalizeWhereCriteria(options ??= {}), so the existing per-keyoptions?.null ?? "throw"/?.undefined ?? "throw"fallbacks apply. The write path now matches the read path:{ text: null }/{ text: undefined }→ throws by default[{ text: null }, { id: 1 }]→ throws by default{ category: { name: null } }→ throws by defaultFindOperator/Date/Buffer/ primitives → pass through unchanged (theisPlainObjectguard from fix(query-builder): reject empty where criteria on update and delete operations #12629 runs before the key loop) — sodelete(entityInstance)and the tree-repository soft-delete paths are unaffectedignore/sql-null→ unchangedNo read-path change (already correct); the #12629 empty-criteria (
WHERE 1=1) guards stay.Notes
v0line keeps the lenient write default (it carries only fix(query-builder): reject empty where criteria on update and delete operations #12629's empty-criteria fix).ignore/ strip) needs entity metadata and is intentionally left as a follow-up.Tests
invalidWhereValuesBehavior default (unconfigured)block:delete/update/softDeletethrow on null/undefined by default; array-criteria null throws; entity-instance passthrough (no throw, deletes its row); read/write parity (findByalso throws).normalizeWhereCriterianow throws by default with no options (and with empty{}options); entity/Date/Uint8Array/primitive passthrough retained.