fix(orm): keep nested partial-select object when leftJoin first column is null#5797
Open
barobaonguyen wants to merge 1 commit into
Open
fix(orm): keep nested partial-select object when leftJoin first column is null#5797barobaonguyen wants to merge 1 commit into
barobaonguyen wants to merge 1 commit into
Conversation
…n is null mapResultRow marks a nested-object path for nullification on the first column it sees being null. The flag was only cleared when a column from a different table appeared under the same path, so non-null values from the same nullable left-joined table never reset it. Reset the flag whenever a non-null value arrives for the same nested path. Add regression tests covering the issue repro, column-order control, all-null nullable/inner joins, mixed-table keys, and two independent nested objects with different null patterns. Closes drizzle-team#1603
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.
Closes #1603.
Root cause
mapResultRow(drizzle-orm/src/utils.ts) builds a per-rownullifyMapthat decides which nested-object paths should be replaced withnullwhen their left-joined table didn't match. The flag for a path is set on the first column it sees beingnull, and only cleared when a column from a different table later appears under the same path.When the second (and later) columns under that path come from the same nullable left-joined table, the existing branch isn't taken — even if those columns are non-null. So a select like:
returns
branding: nullinstead ofbranding: { logo: null, panelBackground: "#1a8cff" }. Swapping the column order in the select hides the bug, which matches every report on the issue.Fix
Also clear the flag when a non-null value arrives for the same path, not only on a table mismatch. Two-line condition change in
mapResultRow:Tests
New
drizzle-orm/tests/mapResultRow.test.ts(pnpm test→ 7 new, 573 total passing):joinsNotNullableMap→ unchanged behaviourPrior art
Equivalent one-line variants land in #1825 (2024), #5436, #5750, #5765, #5785, #5793. None of those PRs ship a regression-test file; the new test covers the surrounding invariants so the bug stays fixed under future refactors of
nullifyMap.