Repository navigation
fix(entity-manager): validate where criteria in increment/decrement - #12692
Conversation
commit: |
Code Review by Qodo
1. Outdated helper JSDoc
|
1783685 to
7fd52a1
Compare
increment() and decrement() built their UPDATE directly via createQueryBuilder().update().set().where(conditions), bypassing normalizeAndValidateWhereCriteria. An empty criteria therefore ran an unfiltered UPDATE against every row, and a configured invalidWhereValuesBehavior was ignored for null/undefined values — unlike update/delete/softDelete/restore. Route conditions through normalizeAndValidateWhereCriteria so increment and decrement reject empty criteria and honor invalidWhereValuesBehavior, consistent with the other write methods.
7fd52a1 to
25b4692
Compare
| .where(conditions) | ||
| .execute() | ||
| if (isPrimitive) { | ||
| qb.whereInIds(whereCriteria) |
There was a problem hiding this comment.
This line would never be reached.
However, I'm thinking we could call EntityManager.update which would already handle the validation part.
|
@naorpeled I'd simply make This would ease maintaining them in general in the future, since we wouldn't have to think about them anymore. |
|
…12692) Co-authored-by: copilot-swe-agent[bot] <[email protected]> (cherry picked from commit 8a51b75) Co-authored-by: Lucian Mocanu <[email protected]>
…12692) Co-authored-by: copilot-swe-agent[bot] <[email protected]> (cherry picked from commit 8a51b75) Co-authored-by: Lucian Mocanu <[email protected]>



Problem
EntityManager.increment()/decrement()(and theRepositorymethods that delegate to them) built theirUPDATEdirectly:This bypassed
normalizeAndValidateWhereCriteria— the guard thatupdate/delete/softDelete/restoreuse. Two consequences:increment(User, {}, "points", 1)renderedUPDATE user SET points = points + 1with noWHERE— every row. This is the sameWHERE 1=1mass-update class of bug the empty-criteria guard was added to prevent. (Intentional all-row updates already haveupdateAll.)invalidWhereValuesBehaviorwas ignored fornull/undefinedvalues in the criteria, unlike the other write methods.Flagged in review of #12690.
Change
Route
conditionsthroughnormalizeAndValidateWhereCriteriain bothincrementanddecrement, mirroringupdateexactly (including theisPrimitive→whereInIdsbranch). They now reject empty criteria and honorinvalidWhereValuesBehavior, consistent with the other write methods.No change to the QueryBuilder layer; low-level
.where()remains intentionally exempt.Tests
repository-increment/repository-decrement: empty{}criteria throwsEmpty criteria(s)and leaves all rows untouched; withinvalidWhereValuesBehavior: { null: "throw" }configured, anullin the criteria throwsNull value encountered.Note
This is a behavior change: an empty criteria that previously ran silently now throws — the intended, safer default (consistent with #12629 for
update/delete).