Skip to content

fix: SQLite date-like column edits producing NaN - #1550

Merged
sorenbs merged 2 commits into
mainfrom
fix/1361-sqlite-date-nan
Jul 18, 2026
Merged

fix: SQLite date-like column edits producing NaN#1550
sorenbs merged 2 commits into
mainfrom
fix/1361-sqlite-date-nan

Conversation

@sorenbs

@sorenbs sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Fixes #1361

Root cause

SQLite reduces declared column types to affinities; datetime/date/timestamp get NUMERIC affinity, which the adapter mapped to the UI's numeric input group. Numeric cells then coerced input unconditionally with Number(...) in two places (NumericInput's save handler and coerceToValue's numeric branch), so a value like 2021-11-01 22:30:00 became NaN and was written.

Fix — never write NaN

  1. Introspection: date-like declared types keep their truthful NUMERIC affinity but get input group string, so Studio edits/stores them as text (SQLite's own affinity conversion still applies on write).
  2. Coercion guards: coerceToValue and NumericInput only coerce when the input actually parses as a number; otherwise the raw text passes through — matching SQLite's NUMERIC-affinity semantics where non-numeric text is stored as TEXT.

Verification

  • Tests written failing-first (the NumericInput test literally captured NaN being submitted), including an end-to-end update test asserting typeof(datetime) = 'text'.
  • Full pnpm test: 928 tests passing; typecheck/lint clean; changeset included; staging rule documented in Architecture/cell-editing.md.

Note: header badges still show the NUMERIC affinity for these columns — displaying declared types is #1386's scope.

🤖 Generated with Claude Code

SQLite columns declared as date/datetime/timestamp get NUMERIC affinity,
so Studio grouped them as numeric and coerced date-string edits to NaN.

- Introspect date-like declared types with group "string" so their
  values are edited and stored as text, matching other SQLite tools.
- Never coerce to NaN: NumericInput and coerceToValue only produce a
  number when the input actually parses as one, otherwise the raw text
  is kept (SQLite NUMERIC affinity stores non-numeric text as TEXT).

Fixes #1361

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: f8330d6d-5122-49d3-8f02-152a43a9d691

📥 Commits

Reviewing files that changed from the base of the PR and between 6fdc396 and 8dd1489.

📒 Files selected for processing (2)
  • data/sqlite-core/datatype.test.ts
  • data/sqlite-core/datatype.ts

Walkthrough

SQLite introspection now assigns date-like NUMERIC-affinity columns to the string datatype group. Numeric conversion and input submission preserve non-numeric text instead of producing NaN, while empty input remains null. Adapter, conversion, and input tests cover these behaviors, and documentation plus a patch changeset record the updated editing contract.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely describes the main change: preventing NaN when editing SQLite date-like columns.
Description check ✅ Passed The description matches the PR and explains the SQLite date-like NaN fix, tests, and documentation.
Linked Issues check ✅ Passed The code changes satisfy #1361 by treating date-like SQLite columns as text and avoiding NaN coercion.
Out of Scope Changes check ✅ Passed The docs, tests, changeset, and Vitest config all support the same fix; no unrelated changes stand out.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1361-sqlite-date-nan
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/1361-sqlite-date-nan

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

@github-actions

Copy link
Copy Markdown
Contributor

Compute preview deployed.

Branch: fix/1361-sqlite-date-nan
Service: fix-1361-sqlite-date-nan
Preview: https://byvlu24qm1has252ggksg22m.cdg.prisma.build

@sorenbs

sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@data/sqlite-core/datatype.ts`:
- Line 39: Update DATE_LIKE_DECLARED_TYPE_REGEX to match DATE or TIME as
declared-type tokens rather than arbitrary substrings, preventing types such as
CANDIDATE from being classified as strings. Add a regression case covering
CANDIDATE and preserve date/time matching behavior for valid declared types.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 60c7f7af-7e8e-4926-8d1e-6314a06e0878

📥 Commits

Reviewing files that changed from the base of the PR and between 81354ff and 6fdc396.

📒 Files selected for processing (13)
  • .changeset/sqlite-date-like-columns-text.md
  • Architecture/cell-editing.md
  • FEATURES.md
  • data/sqlite-core/adapter.test.ts
  • data/sqlite-core/adapter.ts
  • data/sqlite-core/datatype.test.ts
  • data/sqlite-core/datatype.ts
  • data/sqlite-core/introspection.test.ts
  • lib/conversionUtils.test.ts
  • lib/conversionUtils.ts
  • ui/studio/input/NumericInput.test.tsx
  • ui/studio/input/NumericInput.tsx
  • vitest.config.ts

Comment thread data/sqlite-core/datatype.ts Outdated
The date-like check used a bare /DATE|TIME/ substring match, so
NUMERIC-affinity declared types like CANDIDATE, DATED, or RUNTIME were
misclassified as date-like. Use word-boundary token matching instead,
which still covers modifiers like DATETIME(6) and TIMESTAMP WITH TIME
ZONE, and add near-miss regression cases.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sorenbs
sorenbs merged commit cb4f6d5 into main Jul 18, 2026
3 checks passed
@sorenbs
sorenbs deleted the fix/1361-sqlite-date-nan branch July 18, 2026 13:01
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.

Mishandling of date-like columns in SQLite results in NaN.

1 participant