fix nested partial select returning null on left join#5808
Open
ThaiTrevor wants to merge 4 commits into
Open
Conversation
Closes drizzle-team#1188 mysql2 returns BINARY/VARBINARY columns as Node Buffer, but drizzle-orm inferred them as `string` and lossily called `.toString()` on the Buffer in `mapFromDriverValue`, corrupting arbitrary binary content (e.g. a UUID stored as `binary(16)`). Align the column data type with the driver: - `dataType` is now `'buffer'` (same convention as `sqlite-core` blob in buffer mode). - The inferred `data` type is `Buffer`; `driverParam` accepts `Buffer | string` since mysql2 also accepts hex strings. - `mapFromDriverValue` returns the `Buffer` as-is (or wraps a `Uint8Array`/`string` via `Buffer.from`). Updates the type-test default values and the mysql "all types" integration test expectations to use `Buffer` accordingly.
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.
Summary
Fixes nested partial select wrongly collapsing to
nullon a left join when only the first column in the nested object is null.In
mapResultRow(drizzle-orm/src/utils.ts),nullifyMap[objectName]is seeded from the first column of a nested object and is only updated later when a column comes from a different table. That meant: if the first column of a left-joined nested object happened to be null but the remaining columns from the same joined table had non-null values, the object was still nullified — losing real data.The check now also clears the nullify marker when a same-table column has a non-null value, so the object is only nullified when all of its joined columns are null.
Changes
drizzle-orm/src/utils.ts— extendnullifyMapupdate to reset tofalsewhen a non-null value is seen from the same joined table.drizzle-orm/tests/mapResultRow.test.ts— regression tests covering: first column null + others non-null (object kept), all columns null (object nullified), first column non-null + others null (object kept).Closes #1603
Test plan
pnpm test tests/mapResultRow.test.ts— 3 new tests passpnpm test— 545 tests pass; 2 unrelated sqlite test files fail to load due to better-sqlite3 native binding not compilable in the sandbox (missing Visual Studio), no behaviour regression.