Repository navigation
fix(upsert): prevent input entity mutation during upsert result merge - #12155
mbursali93 wants to merge 7 commits into
Conversation
Review Summary by QodoPrevent input entity mutation in upsert operations
WalkthroughsDescription• Prevent input entity mutation during upsert result merge • Skip merging generated values when onUpdate is set • Add comprehensive test coverage for upsert behavior - Verify no mutation on insert operation - Verify no mutation on update operation - Verify normal insert still mutates entity Diagramflowchart LR
A["Upsert Operation"] --> B["ReturningResultsEntityUpdator"]
B --> C{"expressionMap.onUpdate set?"}
C -->|Yes| D["Skip merge to input entity"]
C -->|No| E["Merge generated values"]
D --> F["Return generated map"]
E --> F
File Changes1. src/query-builder/ReturningResultsEntityUpdator.ts
|
Code Review by Qodo
|
521beda to
d05929c
Compare
|
Persistent review updated to latest commit d05929c |
d05929c to
a889801
Compare
|
Persistent review updated to latest commit a889801 |
|
Persistent review updated to latest commit 9227b18 |
|
Persistent review updated to latest commit 6a0542e |
|
|
Persistent review updated to latest commit da1235d |
|
|
Persistent review updated to latest commit 3398db6 |
|
This repository was recently restructured into a pnpm workspace, and the If your branch has diverged enough that a full rebase isn't worth it, Sorry for the disruption, and thanks for your patience. |
|
Thanks for the groundwork here. I opened #13029 which takes a slightly different approach to the same issue (#12094) and is rebased onto the current pnpm workspace layout, since this branch now conflicts after the repo restructure. The main difference: instead of skipping the merge entirely when Flagging it here so reviewers don't end up looking at both. Happy to fold in anything from your tests if useful. |
|
hey @ElwinErnst. it seems your approach is a better one.. thanks for the contribution |



Upsert queries (INSERT ... ON DUPLICATE KEY UPDATE) internally use
ReturningResultsEntityUpdator which merges generated values into
the provided entity.
This mutates the input object passed to repository.upsert().
This change skips merging generated values into the input entity
when expressionMap.onUpdate is set.
Insert behavior remains unchanged.
Added tests to verify:
Fixes #12094