Skip to content

[miniflare] fix: emit valid SQL literal for Infinity/-Infinity in D1 export - #15420

Open
manthaaaaan wants to merge 6 commits into
cloudflare:mainfrom
manthaaaaan:fix/d1-export-infinity
Open

[miniflare] fix: emit valid SQL literal for Infinity/-Infinity in D1 export#15420
manthaaaaan wants to merge 6 commits into
cloudflare:mainfrom
manthaaaaan:fix/d1-export-infinity

Conversation

@manthaaaaan

@manthaaaaan manthaaaaan commented Aug 29, 2026

Copy link
Copy Markdown

Fixes #15378 (partially — the Infinity/-Infinity bare-identifier bug only. The int64 precision issue reported in the same issue is a separate, larger fix that needs its own discussion, since the value loses precision upstream before this code even runs.)

What this fixes

When a REAL column contained Infinity or -Infinity, dumpSql emitted the raw JavaScript string representation ("Infinity" / "-Infinity") directly into the generated SQL. SQLite doesn't recognize these as numeric literals — it parses them as bare identifiers — so re-importing D1's own export failed with: "no such column: Infinity at offset 45: SQLITE_ERROR"

The fix

In packages/miniflare/src/workers/d1/dumpSql.ts, non-finite numbers are now detected and emitted as 9e999 / -9e999 instead of their raw JS string form. This matches the approach SQLite's own .dump command uses — 9e999 is a valid numeric literal that overflows to Infinity on parse, so it round-trips correctly.

Testing

Added a new test, "dumpSql exports Infinity and -Infinity as valid, re-importable SQL literals", in packages/miniflare/test/plugins/d1/suite.ts. It:

  • Creates a table with a REAL column and inserts Infinity and -Infinity
  • Exports via the PRAGMA miniflare_d1_export pragma
  • Asserts the dump does not contain the raw Infinity/-Infinity tokens as bare identifiers
  • Re-imports the dump into a fresh database and confirms it succeeds
  • Confirms the re-imported values are exactly Infinity and -Infinity

Test passes locally (pnpm test suite.ts -t "Infinity"), and the full build passes with no new type errors.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal bug fix to SQL literal generation; no user-facing behavior, config, or docs change.

A picture of a cute animal (not mandatory, but encouraged)
images


Devin Review

@changeset-bot

changeset-bot Bot commented Aug 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3d7b298

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 8 packages
Name Type
miniflare Patch
@cloudflare/deploy-helpers Patch
@cloudflare/pages-shared Patch
@cloudflare/remote-bindings Patch
@cloudflare/runtime-types Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-plugin Patch
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 29, 2026
@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team August 29, 2026 16:01
@workers-devprod

workers-devprod commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/fix-d1-export-infinity.md: [@cloudflare/wrangler]
  • packages/miniflare/src/workers/d1/dumpSql.ts: [@cloudflare/wrangler]
  • packages/miniflare/test/plugins/d1/suite.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration 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.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Aug 29, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@15420

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@15420

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@15420

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@15420

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@15420

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@15420

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@15420

miniflare

npm i https://pkg.pr.new/miniflare@15420

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@15420

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@15420

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@15420

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@15420

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@15420

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@15420

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@15420

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@15420

wrangler

npm i https://pkg.pr.new/wrangler@15420

commit: 3d7b298

@dario-piotrowicz
dario-piotrowicz requested review from dario-piotrowicz and removed request for emily-shen September 10, 2026 13:38

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix @manthaaaaan 😄

Looks good to me, beside some small suggestions 🙂

const [dumpStatements] = result as [string[]];
const dump = dumpStatements.join("\n");

// The dump must not contain the raw JS token as a bare identifier

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// The dump must not contain the raw JS token as a bare identifier
// The dump must not contain the raw JS Infinity/-Infinity tokens as bare identifiers

Comment on lines +683 to +685
// exec(dump) must not throw — this is the core guarantee of the fix.
// (If the dump contained bare `Infinity`/`-Infinity` identifiers, SQLite
// would reject them at parse time and exec would throw.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

outside of the context of this PR the sentence "this is the code guarantee of the fix" doesn't have any meaning

I would simplify this comment:

Suggested change
// exec(dump) must not throw — this is the core guarantee of the fix.
// (If the dump contained bare `Infinity`/`-Infinity` identifiers, SQLite
// would reject them at parse time and exec would throw.)
// exec(dump) must not throw, If the dump contained the bare `Infinity`/`-Infinity`
// identifiers, SQLite would reject them at parse time and exec would throw

Comment on lines +688 to +690
// Assert the exported SQL actually contains the correctly-signed literal
// for each row — this is the real guarantee of the fix, checked before
// the D1 JS binding's Infinity->null normalisation can hide it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as above, I would really avoid mentioning "the fix":

Suggested change
// Assert the exported SQL actually contains the correctly-signed literal
// for each row — this is the real guarantee of the fix, checked before
// the D1 JS binding's Infinity->null normalisation can hide it.
// Assert the exported SQL actually contains the correctly converted value for each row

@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

D1 export silently corrupts INTEGER values outside JavaScript's safe range (and emits invalid SQL for ±Infinity)

3 participants