Skip to content

[wrangler] fix: normalize CRLF before sending D1 commands to the remote query API - #15044

Merged
petebacondarwin merged 3 commits into
cloudflare:mainfrom
stareezy-1:fix/14991-d1-crlf-migrations
Aug 15, 2026
Merged

petebacondarwin merged 3 commits into
cloudflare:mainfrom
stareezy-1:fix/14991-d1-crlf-migrations

Conversation

@stareezy-1

@stareezy-1 stareezy-1 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14991

wrangler d1 migrations apply --remote failed with incomplete input: SQLITE_ERROR [7500] whenever a migration file had CRLF line endings and contained a CREATE TRIGGER ... BEGIN ... END; body — the default situation for Windows checkouts with core.autocrlf=true.

Root cause: migrations apply --remote sends the whole migration (plus the tracking INSERT) as one sql string to the D1 /query endpoint, which splits multi-statement SQL on ; server-side and mishandles structural CRLF inside compound statement bodies. The identical bytes succeed via execute --remote --file because that path uses the D1 import API; the client-side splitter is not involved in the command path.

Fix: normalize only structural CRLF before sending commands to the remote query API. The SQL-aware normalizer preserves CRLF inside single-, double-, backtick-, and bracket-quoted content, including doubled quote escapes, so remote execution does not silently change stored values.

Verification: all 16 D1 splitter tests, 16 D1 execute tests, and 33 D1 migration tests pass. The repository-wide pnpm check also passes.


  • Tests
    • Tests included/updated
  • Public documentation
    • Documentation not necessary because: bug fix in an existing command path; no user-facing configuration or API surface changes

Note

This is a contribution from an AI agent: stareezy-1.


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1b7cd77

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

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers 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

@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team August 5, 2026 17:08
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/d1
  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/d1-crlf-remote-query.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/d1/execute.test.ts: [@cloudflare/d1 @cloudflare/wrangler]
  • packages/wrangler/src/d1/execute.ts: [@cloudflare/d1 @cloudflare/wrangler]

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread packages/wrangler/src/d1/execute.ts Resolved
@petebacondarwin
petebacondarwin marked this pull request as draft August 11, 2026 20:19
@stareezy-1
stareezy-1 marked this pull request as ready for review August 12, 2026 07:33
@workers-devprod

workers-devprod commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/d1
  • ✅ @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/d1/execute.test.ts: [@cloudflare/d1]
  • packages/wrangler/src/tests/d1/splitter.test.ts: [@cloudflare/d1]
  • packages/wrangler/src/d1/execute.ts: [@cloudflare/d1]
  • packages/wrangler/src/d1/splitter.ts: [@cloudflare/d1]

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 12, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk Aug 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

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

@cloudflare/config

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@15044

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 1b7cd77

@stareezy-1

Copy link
Copy Markdown
Contributor Author

CI status: I audited all 22 failing checks. They are unrelated to the D1 change: the failing jobs generate compatibility date 2026-08-12, while the pinned workerd binary supports only through 2026-08-11.

The same repository-wide failure is affecting Cloudflare-authored PR #15143 and matches #14942. The focused D1 tests and pnpm check pass, so I have kept this branch scoped to #14991; the failed jobs should be rerun after the upstream runtime bump or compatibility-date fix lands.

@petebacondarwin
petebacondarwin force-pushed the fix/14991-d1-crlf-migrations branch from 5cef407 to 3bfce39 Compare August 14, 2026 10:05
The D1 query API splits multi-statement SQL on ';' server-side and
mishandles CRLF line endings inside compound statements such as a CREATE
TRIGGER ... BEGIN ... END; body, producing 'incomplete input: SQLITE_ERROR'.
wrangler d1 migrations apply --remote sends the whole migration (plus the
tracking INSERT) as one command string, so CRLF migrations with triggers
failed while the same bytes via the import-based execute --remote --file
succeeded. Normalize CRLF to LF in the command path before sending.

Closes cloudflare#14991.
- Remove the conventional-commit prefix from the changeset title
  (REVIEW.md forbids type prefixes in changeset titles).
- Re-indent the new execute test to the describe nesting level and apply
  oxfmt so the repository formatting check passes.
@petebacondarwin
petebacondarwin force-pushed the fix/14991-d1-crlf-migrations branch from 3bfce39 to 1b7cd77 Compare August 14, 2026 12:30

@petebacondarwin petebacondarwin 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 bypass

@petebacondarwin
petebacondarwin enabled auto-merge (squash) August 15, 2026 11:13

@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

@petebacondarwin
petebacondarwin merged commit b7422b0 into cloudflare:main Aug 15, 2026
73 of 76 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in workers-sdk Aug 15, 2026
Brooooooklyn added a commit to voidzero-dev/void that referenced this pull request Nov 18, 2026
Direct D1 files up to 100 KB now go through `cf d1 query`, which sends
the SQL as is. The query API fails on CRLF inside a trigger body with
SQLITE_ERROR 7500, while the import API took the same bytes. A small
scanner turns structural CRLF into LF and keeps line endings inside
quoted values and identifiers, like wrangler's fix in
cloudflare/workers-sdk#15044.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

D1: 'wrangler d1 migrations apply --remote' fails with 'incomplete input: SQLITE_ERROR' on CRLF migration files containing triggers

3 participants