You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(orm): keep null on optional Boolean fields on MySQL and SQLite - #2924
On MySQL and SQLite, transformInput turns a Boolean into 1 or 0 with value ? 1 : 0, so null becomes 0. Writing null to a Boolean? field stores false, as the issue describes. The issue mentions MySQL, but sqlite.ts has the same line.
Filters go through the same function, so { flag: { equals: null } } becomes flag = 0 and returns the false rows instead of the NULL ones. { flag: null } already worked, because it's turned into IS NULL before it gets there.
The fix keeps null as null in 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 whatever TEST_DB_PROVIDER is set:
writes null with create, update, createMany and updateMany, then checks that all four rows match flag: null and none match flag: false
equals: null finds only the row whose flag was never set, and not: { equals: null } counts the other two
On dev both 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.4
tests/e2e: 1127 passed on SQLite
the other packages' tests pass on both
lint and the regression tsc are clean
Thanks @aamarin for the clear report and for pointing at the right line.
Summary by CodeRabbit
Bug Fixes
Optional Boolean values set to null are now preserved when creating or updating records in MySQL and SQLite.
Filtering for null and false Boolean values now returns the expected results.
Tests
Added regression coverage for creating, updating, and filtering records with optional Boolean fields.
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.
Fixeszenstackhq#2918
Reviewing files that changed from the base of the PR and between dbe47ba and 3ee86bb.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
MySQL and SQLite now preserve null Boolean inputs instead of converting them to zero. Regression tests cover create and update operations, omitted values, and null-related filters.
Both dialects preserve null Boolean inputs and retain the existing conversion for non-null values. Regression tests cover explicit null values in create and update operations, omitted values, and null-related filters.
This change keeps null values on optional Boolean fields for MySQL and SQLite instead of storing them as false. The change is small and covered by new regression tests, so merge risk is minimal.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: optional Boolean fields keep null instead of being stored as 0 on MySQL and SQLite. The raw summary confirms the dialect changes in mysql.ts and sqlite.ts, and the obj…
Linked Issues check
Issue #2918 requires that writing null to an optional Boolean? field on MySQL stores NULL and reads back as null, for create and update. The issue names the cause: the Boolean case in MySqlCrudDialect…
Out of Scope Changes check
The PR changes two lines in the Boolean case of transformInput: one in mysql.ts (the issue's scope) and one in sqlite.ts. The sqlite.ts change applies the same fix to the same defect, which the PR des…
Full details: Title check
Explanation
The title names the main change: optional Boolean fields keep null instead of being stored as 0 on MySQL and SQLite. The raw summary confirms the dialect changes in mysql.ts and sqlite.ts, and the objectives confirm the same fix for issue #2918. The title is specific and matches the changeset.
Full details: Linked Issues check
Explanation
Issue #2918 requires that writing null to an optional Boolean? field on MySQL stores NULL and reads back as null, for create and update. The issue names the cause: the Boolean case in MySqlCrudDialect.transformInput returns value ? 1 : 0, which maps null to 0. The reviewed diff (mergeBase to head) changes that case to value !== null ? (value ? 1 : 0) : value, which matches the Decimal guard the issue suggests. Non-null values keep their 1/0 mapping. The PR also adds tests/regression/test/issue-2918.test.ts (per the summary, +42 lines) that cover create, update, createMany and updateMany with null, and equals: null filters. The regression tests were not run during this review. The test results come from the author's description and were not independently verified. The code change alone establishes the write-path behavior requested by the issue.
Full details: Out of Scope Changes check
Explanation
The PR changes two lines in the Boolean case of transformInput: one in mysql.ts (the issue's scope) and one in sqlite.ts. The sqlite.ts change applies the same fix to the same defect, which the PR description says exists there too. It is not an unrelated change. The equals: null filter behavior changes as a side effect, because filter values pass through the same transformInput function. The PR description and the regression test cover this case, so it is part of the same defect. The new regression test file is supporting test coverage for the objective. No unrelated changes were found in the reviewed diff for mysql.ts and sqlite.ts. The file list for the full head was truncated, so other files were not individually inspected. The summary lists only the three files above.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between 0ea2711 and dbe47ba.
Files selected for processing: 3
packages/orm/src/client/crud/dialects/mysql.ts
packages/orm/src/client/crud/dialects/sqlite.ts
tests/regression/test/issue-2918.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ymc9, could you approve the workflows for this PR when you have a moment? Build and Test is still waiting for approval, so the new regression test hasn't run in CI yet. Locally it passes on SQLite, MySQL 8.4 and PostgreSQL 16.
@ymc9, could you approve the workflows for this PR when you have a moment? Build and Test is still waiting for approval, so the new regression test hasn't run in CI yet. Locally it passes on SQLite, MySQL 8.4 and PostgreSQL 16.
Sure. Just started them. I'll finish reviewing this PR short. Thanks for the wait!
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
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.
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.