Repository navigation
fix(core): match reloaded rows in upsertMany when inputs use different unique keys - #8396
Merged
Merged
Conversation
…ent unique keys Without RETURNING support, the reload query and the row matching used the unique key of the first input for the whole batch, and compared the reloaded rows on the keys of every condition at once. Inputs identified by another unique key (or by the primary key) failed with `Cannot find matching entity for condition`, or could be matched to an unrelated row.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8396 +/- ##
==========================================
+ Coverage 96.60% 99.66% +3.06%
==========================================
Files 293 293
Lines 32030 32040 +10
Branches 9197 8630 -567
==========================================
+ Hits 30941 31934 +993
+ Misses 1083 102 -981
+ Partials 6 4 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…n `upsertMany` Narrowing the reloaded row to the keys of the condition turned an empty condition into a match for every row. Compare the full row in that case, as before.
B4nan
enabled auto-merge (squash)
October 5, 2026 19:34
…mpty condition Deriving the reload fields per row turned a row without any unique value into an empty `$or` branch, which matched every row and let the row be hydrated from an unrelated one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On drivers without RETURNING,
em.upsertMany()reloads the rows and matches each input to its row. Both the reload query and the matching assumed every input in the batch is identified by the same unique key as the first one. A batch where one row is identified by a uniquecodeand another by a composite unique (or by the primary key) threwCannot find matching entity for condition ....The reload query now builds each
$orbranch from that row's own condition, and the reloaded rows are compared only on the keys of the condition being matched. The first part matters on its own: with the first row's key applied to all rows, anullin that column becamecode is null, which over-fetched and could hydrate an input from an unrelated row.This does not change the
ON CONFLICTtarget, which is still derived from the first row only. On SQLite and PostgreSQL a mixed batch therefore works for inserts, but hits a unique constraint violation when a row identified by a different key already exists.