Repository navigation
fix(query-builder): guard nulls in orderBy object shorthand - #12706
Conversation
Code Review by Qodo
1.
|
commit: |
|
Friendly ping — this has been approved and CI has been green for over a week. Let me know if anything is needed before merge. |
|
This repository was recently restructured into a pnpm workspace, and the If your branch has diverged enough that a full rebase isn't worth it, Sorry for the disruption, and thanks for your patience. |
When orderBy is called with an object like { order: 'ASC' } (no nulls
field), the generated SQL contained a literal 'undefined' token:
ORDER BY "col" ASC undefined
causing a syntax error on all drivers.
The concatenation at buildOrderByExpression unconditionally appended
' ' + obj.nulls even when nulls was undefined. Guard it so the
space+nulls segment is only emitted when nulls is a non-empty value.
…and add regression test
44b7a83 to
1b7952b
Compare
Problem
When
orderByis called with the object shorthand and nonullsproperty, the generated SQL contains a literalundefinedtoken, producing a syntax error on all drivers.Reproduction (SQLite):
nullsis typed as optional inOrderByCondition, so{ order: 'ASC' }is valid, but the value ends upundefinedat runtime.Root cause
SelectQueryBuilder.buildOrderByExpression(around line 2608) unconditionally concatenated:When
nullsisundefined, that produces"ASC undefined".Fix
Guard the nulls segment so it is only appended when the value is present:
Reproduction confirmed on
masterTested with SQLite. The
ORDER BY "post"."id" ASC undefinederror is reproducible on currentmasterand is resolved by this change.Closes #8103