Skip to content

D1 /query rejects LF-only multi-statement SQL ending in an uppercase-BEGIN trigger #113

Open

Description

@jmcmacnz

Minimal reproduction and result

Send one documented { "sql": "..." } request to D1 /query containing six CREATE TABLE statements followed by one multiline trigger. This sanitized example shows the relevant shape without application names or columns:

CREATE TABLE item_1 (id INTEGER PRIMARY KEY, value TEXT);
CREATE TABLE item_2 (id INTEGER PRIMARY KEY);
CREATE TABLE item_3 (id INTEGER PRIMARY KEY);
CREATE TABLE item_4 (id INTEGER PRIMARY KEY);
CREATE TABLE item_5 (id INTEGER PRIMARY KEY);
CREATE TABLE item_6 (id INTEGER PRIMARY KEY);
CREATE TRIGGER item_1_after_insert
AFTER INSERT ON item_1
BEGIN
  UPDATE item_1 SET value = value WHERE id = NEW.id;
END;

The observed request used the same shape with six tables and one unchanged multiline trigger. It was LF-only (zero CR bytes), used uppercase BEGIN, and was submitted in one OpenAPI-supported {sql} request. The generic SQL above is a redaction, not a claim that those exact bytes were separately tested remotely.

Observed: local SQLite accepted the SQL and created all seven objects. Remote /query returned HTTP 400, code 7500, incomplete input: SQLITE_ERROR; a follow-up query found the remote schema empty.

Expected: /query accepts the valid multi-statement SQL and creates the six tables and trigger.

A semantically equivalent single-line trigger succeeds locally, but it had not been tested remotely when this report was filed.

Versions and scope

  • Alchemy 2.0.0-beta.77 produced the joined SQL; Wrangler was not involved in the failing request.
  • The request went directly through the public D1 REST contract.

This appears distinct from the CRLF case in cloudflare/workers-sdk#14991, fixed by cloudflare/workers-sdk#15044, and the lowercase-begin case in cloudflare/workers-sdk#15314: this request is LF-only and uses uppercase BEGIN. The older multiline-trigger reports cloudflare/workers-sdk#4998 and cloudflare/workers-sdk#15178 may still be related because they also distinguish /query parsing from other execution paths.

Could the D1 team confirm whether the server-side /query splitter is expected to accept a multi-statement string whose final statement is a multiline trigger? Is there another token or statement-boundary condition maintainers would like isolated in a further sanitized reproduction?

This report was generated with AI assistance and approved by a human.

Activity

  1. workers-devprod commented on Sep 17, 2026

    @workers-devprod
    Collaborator

    Automated triage

    Issue assessment

    • Actionability: ✅ Actionable.
    • Type: Bug.
    • Reproduction: Automatic attempt requested.
    • Labels:
      • product:d1 (high)
      • api (medium)
    Actionability and missing information

    D1 REST /query returns HTTP 400 code 7500 incomplete input: SQLITE_ERROR for LF-only multi-statement SQL (six CREATE TABLEs plus one multiline uppercase-BEGIN trigger) that local SQLite accepts; sanitized example was not remotely verified and single-line variant untested remotely.

    Reproduction reason: Report describes a concrete current-behavior defect with a testable SQL shape (LF-only multi-statement string ending in an uppercase-BEGIN multiline trigger) and an observed HTTP 400 incomplete-input error; no suspicious or redirecting content.

    Missing information:

    • minimal reproduction

    Reproduction

    • Result: ⚠️ Blocked.
    • Summary: Blocked: the reported HTTP 400 (code 7500) is produced by the remote D1 REST /query endpoint, which requires Cloudflare credentials absent from this sandbox. Local splitter and local /query paths accept the reported SQL; local exec() fails with the exact reported error on the reported shape.
    Evidence and attempted steps

    Steps attempted:

    1. Cloned cloudflare/workers-sdk at HEAD 2298cf1 and built all packages per the documented setup (pnpm install --frozen-lockfile and pnpm build; 41/41 turbo tasks OK).
      • Command: git clone https://github.com/cloudflare/workers-sdk.git && cd workers-sdk && pnpm install --frozen-lockfile && pnpm build
    2. Ran the in-repo wrangler D1 splitter (packages/wrangler/src/d1/splitter.ts) on the reported fixture: 7 complete statements, final multiline uppercase-BEGIN trigger intact - no local splitter defect.
      • Command: esbuild packages/wrangler/src/d1/splitter.ts --bundle --format=cjs --platform=node --outfile=splitter-bundle.cjs && node test-splitter.cjs fixture.sql
    3. Exercised the local D1 POST /query handler via the miniflare D1 binding with the joined sql string: accepted, sqlite_master lists 6 tables plus trigger; matches the issue's local observation.
      • Command: node d1-e2e.mjs fixture.sql (db.prepare(joined).all() sends the joined sql to local POST /query)
    4. Isolated fresh-database run of the exact wrangler d1 execute --local path: splitSqlQuery yields 7 statements, db.batch all success, all 7 objects created.
      • Command: node d1-isolated-batch.mjs fixture.sql
    5. Variant matrix on the local workerd D1 exec() API (fresh DB per case): tables-only SUCCESS; single-line trigger SUCCESS; reported multiline-trigger shape ERROR 'incomplete input: SQLITE_ERROR' (exact issue error string).
      • Command: node d1-exec-matrix.mjs
    6. Documented CLI path: wrangler d1 execute repro-db --local --file=fixture.sql exit 0; verification query listed the six tables and the trigger.
      • Command: wrangler d1 execute repro-db --local --file=fixture.sql && wrangler d1 execute repro-db --local --command "SELECT type, name FROM sqlite_master"
    7. Attempted the reported remote surface via the built wrangler CLI to document the credential gate: --remote --file exits 1 requiring CLOUDFLARE_API_TOKEN; the remote POST /query was never sent. Also packaged a standalone pinned project (pnpm reproduce, exit 0) repeating the local checks.
      • Command: wrangler d1 execute repro-db --remote --file=fixture.sql ; cd reproduction-output/project && pnpm install && pnpm reproduce

    Blocker: The reported behavior (HTTP 400, code 7500, 'incomplete input: SQLITE_ERROR') is produced by the remote Cloudflare D1 REST endpoint POST /accounts/(account_id)/d1/database/(id)/query. Exercising it requires a Cloudflare account ID and API token (e.g. CLOUDFLARE_API_TOKEN/CLOUDFLARE_ACCOUNT_ID), which do not exist in this sandbox and which must not be requested or searched for; the built wrangler CLI confirms the gate (exit 1: 'In a non-interactive environment, it's necessary to set a CLOUDFLARE_API_TOKEN environment variable for wrangler to work.'), so the decisive remote request was never sent.

    Artifact: Download reproduction archive (Cloudflare Access required).

    Treat archive contents as untrusted. Inspect them before running anything.


    This summary was generated by an LLM and may contain errors. Please verify its findings.

    Triage bot commands and options

    Repository collaborators with write or admin access can trigger actions by commenting on this issue:

    • @workers-devprod reproduce: Attempt to reproduce the issue using its description and recent comments.
  2. added
    product:d1Relating to Cloudflare D1: https://developers.cloudflare.com/d1/
    on Sep 17, 2026
  3. pokeracetom commented on Oct 10, 2026

    @pokeracetom

    We independently hit a very similar failure with Wrangler 4.92.0 on macOS against an EU D1 database. The Node version was not recorded in the retained run evidence.

    wrangler d1 migrations apply --remote returned:

    incomplete input: SQLITE_ERROR [code: 7500]

    Our migration has 3 tables, 3 unique indexes and 9 triggers: 3 multiline and 6 single-line. All trigger BEGIN/END keywords are uppercase. The 6,989-byte file is LF-only, with no BOM, NUL or non-ASCII bytes.

    One potentially useful difference from #113: the multiline triggers are earlier in the migration. Its last statement is a single-line trigger, then Wrangler appends its migration-ledger INSERT. The combined request therefore ends with an INSERT, not a trigger. Source-based reconstruction gives 7,092 SQL bytes in one sql field, or 7,265 JSON bytes; this is not a captured wire body.

    The installed local path splits statements before executing a batch; the remote path sends the combined SQL string to /query without that client-side split. Local isolation passed 533 cases in each of three paths, including all 511 nonempty trigger combinations. The ledger append also passed locally.

    Post-failure readbacks found identical schema and unchanged migration ledger, no partial objects, zero FK violations and quick_check = ok. This is observed no-change behavior, not proof of general rollback guarantees.

    This looks strongly related, but we have not proved a shared root cause or obtained a minimal remote reproduction. Would the trailing ledger INSERT help narrow down the server-side parsing path? We can provide additional sanitized structural evidence if useful.

  4. evolvehiroyuki-hub commented on Oct 15, 2026

    @evolvehiroyuki-hub

    Hello Cloudflare team,

    We have a similar error, but our client execution path differs from the original report in #113:

    • Original report: Alchemy submits a SQL string directly to the D1 REST /query endpoint; Wrangler was not involved.
    • Our case: the standard wrangler d1 migrations apply --remote command, with Wrangler pinned to 4.92.0, on macOS with Node.js 24.19.0.

    Our remote attempt exited with code 1 and D1 API error 7500 / incomplete input. Prior local standard-migration validation of the same private migration succeeded.

    Relevant differences and observations:

    • Our SQL is LF-only, with no CR, BOM or NUL bytes, and uppercase BEGIN/END.
    • All trigger bodies in the latest remotely attempted SQL were already single-line. A whitespace-only adjustment had not resolved the failure.
    • Our migration file ends with a non-trigger statement. Inspection of the installed Wrangler source indicates that its migration-ledger INSERT is appended to the SQL sent through the remote query path. This is a source-based observation, not a captured wire request.
    • Authentication and read-only target checks succeeded immediately before the attempt.
    • Read-only inspection after the failure found only the empty d1_migrations table: no application tables or triggers, and no applied-migration record. This is an observed result, not proof of a general rollback guarantee.

    We have not established whether this shares the root cause of #113.

    Anonymous local test candidate

    The following SQL uses only generic names. It is not a confirmed minimal remote reproducer:

    CREATE TABLE demo_alpha(id INTEGER PRIMARY KEY, amount INTEGER NOT NULL DEFAULT 0);
    CREATE TABLE demo_beta(id INTEGER PRIMARY KEY, source_id INTEGER NOT NULL REFERENCES demo_alpha(id));
    CREATE INDEX demo_beta_source ON demo_beta(source_id);
    CREATE TRIGGER demo_alpha_created AFTER INSERT ON demo_alpha
    BEGIN
      INSERT INTO demo_beta(id,source_id) VALUES(NEW.id,NEW.id);
      UPDATE demo_alpha SET amount=amount+1 WHERE id=NEW.id;
    END;

    This exact generic candidate succeeded locally with SQLite, the installed Wrangler 4.92.0 splitter plus a local D1 Binding API batch, and wrangler d1 execute --local --file.

    A separate line-oriented local D1 exec() test rejected the multiline candidate and accepted its single-line equivalent. That uses a different API and does not establish the cause of the remote /query failure.

    The generic candidate has not been executed against remote D1. The confirmed remote 7500 belongs to our private application migration. The local standard-migration success above also refers to that private migration; we are not claiming a standard-migration or remote test of this generic candidate.

    Questions

    1. Could the standard Wrangler migration failure be related to the remote parsing problem reported here, despite the single-line triggers and trailing ledger INSERT? What further sanitized evidence would help distinguish this from other causes of error 7500?
    2. What officially supported workaround or confirmed fixed Wrangler version do you recommend? Would separating table/index creation and trigger creation into separate standard migrations help, or is another supported path required?
    3. What atomicity and rollback guarantees apply to the schema changes and d1_migrations entry within one migration? With separate migrations, how should we verify the committed state and safely resume after a later phase fails? If you recommend an import path, how should migration bookkeeping and recovery be preserved?

    We have stopped remote write attempts. We can provide further sanitized observations, but cannot publish private application SQL, account/database identifiers, customer information, credentials or raw logs.

    Thank you.

  5. kanchingyg commented on Oct 25, 2026

    @kanchingyg

    We ran into the same class of local-SQLite-passes vs remote-D1-/query-fails migration bugs (triggers with BEGIN ... END;, explicit BEGIN TRANSACTION blocks, and unguarded FOREIGN KEY DDL) and built an offline pre-flight linter for migrations/*.sql in wrangler-doctor:

    npx wrangler-doctor
    # Checks migrations/*.sql for D1 remote /query splitter & execution hazards (WD201-WD206)

    Running npx wrangler-doctor in CI flags trigger bodies (WD202), explicit transaction statements rejected by remote D1 (WD201), and schema mutations that behave differently between local Miniflare SQLite and the remote D1 /query endpoint before deployment.

  6. moved this from Untriaged to Other in workers-sdkon Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product:d1Relating to Cloudflare D1: https://developers.cloudflare.com/d1/

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions