Skip to content

fix(drizzle-orm): Return an object when any values is non-null during a grouped left/right join (#2157)#5559

Open
AaronGibbison wants to merge 1 commit intodrizzle-team:mainfrom
AaronGibbison:2157-fix-nullable-join-object-lose
Open

fix(drizzle-orm): Return an object when any values is non-null during a grouped left/right join (#2157)#5559
AaronGibbison wants to merge 1 commit intodrizzle-team:mainfrom
AaronGibbison:2157-fix-nullable-join-object-lose

Conversation

@AaronGibbison
Copy link
Copy Markdown

@AaronGibbison AaronGibbison commented Mar 30, 2026

Problem

When deserialising grouped objects, if the first value of an object of a left/right join is null, the entire object is defined as null regardless of the result of later values. Returned results are incomplete, missing data from a successful join.

Root Cause

// drizzle-orm/src/utils.ts
export function mapResultRow<TResult>(...) {
// ...
    // Defines the object a nullable on the first value, but doesn't redefine the object a non-nullable if future values are not null
    if (!(objectName in nullifyMap)) {
        nullifyMap[objectName] = value === null ? getTableName(field.table) : false;
    } else if (typeof nullifyMap[objectName] === 'string' && nullifyMap[objectName] !== getTableName(field.table)) {
        nullifyMap[objectName] = false;
    }
// ...
}

Fix

When mapping grouped objects result, if any values of the object is not-null, then classify the entire object as not-null.

Related

Fixes #2157

@VirtuaBoza
Copy link
Copy Markdown

What a crazy coincidence that you open this on the same day I find another bug in my app related to this. Thanks!

…eft/right join

When doing a grouped left/right join, the entire object is incorrectly defined as null if the first value returned is null.
Further entries are checked for a non-null values, and ensures the returned object is defined if any value was not null
@AaronGibbison AaronGibbison force-pushed the 2157-fix-nullable-join-object-lose branch from ebfd94e to 1816f35 Compare March 31, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Select with left joins returning null for table with non-null results in reality

2 participants