Repository navigation
fix(orm): keep null on optional Boolean fields on MySQL and SQLite - #2924
SibilSoren wants to merge 1 commit into
Conversation
The MySQL and SQLite dialects turned every Boolean input into 1 or 0, so null became 0. Writing null to a Boolean? field stored false, and an equals: null filter matched the false rows instead of the null ones. Keep null as null, like the Decimal case already does. Fixes zenstackhq#2918
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes #2918
On MySQL and SQLite,
transformInputturns a Boolean into1or0withvalue ? 1 : 0, sonullbecomes0. Writingnullto aBoolean?field storesfalse, as the issue describes. The issue mentions MySQL, butsqlite.tshas the same line.Filters go through the same function, so
{ flag: { equals: null } }becomesflag = 0and returns thefalserows instead of theNULLones.{ flag: null }already worked, because it's turned intoIS NULLbefore it gets there.The fix keeps
nullasnullin the Boolean case of both dialects, the same way the Decimal case a few lines below does. PostgreSQL passes booleans through as they are, so it wasn't affected.Tests
New
tests/regression/test/issue-2918.test.ts, which runs on whateverTEST_DB_PROVIDERis set:nullwithcreate,update,createManyandupdateMany, then checks that all four rows matchflag: nulland none matchflag: falseequals: nullfinds only the row whose flag was never set, andnot: { equals: null }counts the other twoOn
devboth tests fail on SQLite and MySQL 8.4 (expected { id: 1, flag: false } to match object { flag: null }) and pass on PostgreSQL 16. With the fix they pass on all three.Locally:
tests/regression: 301 passed on SQLite and on MySQL 8.4tests/e2e: 1127 passed on SQLitelintand the regressiontscare cleanThanks @aamarin for the clear report and for pointing at the right line.
Summary by CodeRabbit
nullare now preserved when creating or updating records in MySQL and SQLite.nullandfalseBoolean values now returns the expected results.