Skip to content

fix(orm): allow setting null on optional Decimal fields when using sqlite provider - #2798

Open
sanny-io wants to merge 4 commits into
zenstackhq:devfrom
sanny-io:fix/sqlite-null-decimals
Open

fix(orm): allow setting null on optional Decimal fields when using sqlite provider#2798
sanny-io wants to merge 4 commits into
zenstackhq:devfrom
sanny-io:fix/sqlite-null-decimals

Conversation

@sanny-io

@sanny-io sanny-io commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Fixes #2797

Summary by CodeRabbit

  • Bug Fixes

    • Optional Decimal fields in SQLite now correctly preserve null values when creating and retrieving records.
    • Non-null Decimal values continue to be handled as expected.
  • Tests

    • Added end-to-end coverage for nullable Decimal fields in SQLite.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 293b1121-2f49-4a62-8a53-d004b5818c2d

📥 Commits

Reviewing files that changed from the base of the PR and between 5ce57de and 0c34a4d.

📒 Files selected for processing (1)
  • tests/e2e/orm/client-api/sqlite-null.test.ts

📝 Walkthrough

Walkthrough

The SQLite dialect now preserves null values for nullable Decimal inputs. A SQLite-specific end-to-end test covers null creation, updating to Decimal(1), and resetting the field to null.

Changes

SQLite Decimal null handling

Layer / File(s) Summary
Preserve nullable Decimal values
packages/orm/src/client/crud/dialects/sqlite.ts, tests/e2e/orm/client-api/sqlite-null.test.ts
The SQLite dialect preserves null and stringifies non-null Decimal values. The end-to-end test validates creation, Decimal updates, and null resets.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The SQLite dialect preserves null for nullable Decimal fields while converting non-null values to strings, meeting issue #2797.
Out of Scope Changes check ✅ Passed The changes are limited to the SQLite Decimal transformation fix and a focused regression test for issue #2797.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the SQLite fix for assigning null to optional Decimal fields.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/e2e/orm/client-api/sqlite-null.test.ts (1)

7-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add update coverage for nullable Decimal values.

Line 17 only verifies the create path. Add an update operation that assigns balance: null and assert that the result contains balance: null. This prevents a regression in update handling from passing the test.

The PR objective includes both create and update operations.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/e2e/orm/client-api/sqlite-null.test.ts` around lines 7 - 25, Extend the
“allows writing null to optional Decimal fields” test after the existing create
assertion to update the created User with balance: null, then assert the update
result contains balance: null. Reuse the created record’s identifier and
existing db.user API so both create and update paths are covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/e2e/orm/client-api/sqlite-null.test.ts`:
- Around line 7-25: Extend the “allows writing null to optional Decimal fields”
test after the existing create assertion to update the created User with
balance: null, then assert the update result contains balance: null. Reuse the
created record’s identifier and existing db.user API so both create and update
paths are covered.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 06fef48d-4f0c-47cd-8b02-f30a561e6e41

📥 Commits

Reviewing files that changed from the base of the PR and between d7c41d8 and 5ce57de.

📒 Files selected for processing (2)
  • packages/orm/src/client/crud/dialects/sqlite.ts
  • tests/e2e/orm/client-api/sqlite-null.test.ts

@sanny-io sanny-io changed the title fix: allow setting null on optional Decimal fields when using sqlite provider fix(orm): allow setting null on optional Decimal fields when using sqlite provider Aug 13, 2026
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.

SQLite dialect: writing null to a nullable Decimal field crashes with "Cannot read properties of null (reading 'toString')"

1 participant