Repository navigation
fix(core): reuse identity-map entries with falsy primary keys - #8757
Merged
B4nan merged 2 commits intoNov 18, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #8757 +/- ##
=======================================
Coverage 99.66% 99.66%
=======================================
Files 294 294
Lines 32867 32867
Branches 8949 8949
=======================================
Hits 32757 32757
Misses 106 106
Partials 4 4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
B4nan
approved these changes
Nov 18, 2026
B4nan
enabled auto-merge (squash)
November 18, 2026 12:06
B4nan
pushed a commit
that referenced
this pull request
Nov 23, 2026
…()` (#8806) With `updateByPrimaryKey` (the default), `assign()` checks `if (pk)` before matching nested data to the existing related entity, both for to-one relations and for collection items. When that primary key is `0` or `''`, the check fails and the data goes through `em.create()` instead, so the existing entity is not updated and the change is silently lost on flush. ```ts const book = await em.findOneOrFail(Book, 1, { populate: ['author'] }); // author.id === 0 wrap(book).assign({ author: { id: 0, name: 'updated' } }); book.author.name; // still the old name ``` This switches both checks to `pk != null`, the same fix #8757 made for the identity map lookup.
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.
UnitOfWork.tryGetById()treats a falsy primary key as missing, even thoughUtils.extractPK()returns valid keys such as0,0n, and an empty string. As a result,findOne()misses entities already in the identity map: managed entities are queried again, and new entries can be flushed unnecessarily instead of being returned directly.Check for a nullish key instead. The SQLite regressions cover all three falsy key types, new unflushed entries, managed lookups using scalar/object conditions, and an additional-condition query that must still reach the database.
Validation: all three regressions fail with the old guard. Twenty tests across four relevant SQLite files pass with the fix. Focused strict TypeScript compilation, type-aware oxlint/type checking, formatting, public-content and whitespace checks pass. The full database test matrix was not run.