Skip to content

Bulk delete fails on Cloudflare D1 with "too many SQL variables" (document lock query binds collections × ids parameters) #19233

Open

Description

@digitalwerber

Describe the Bug

Deleting a handful of documents at once (e.g. selecting several rows in the list view) fails on Cloudflare D1 with too many SQL variables.

The lock handling of bulk operations (getLockedDocumentIds/deleteDocumentLocks in packages/payload/src/utilities/checkDocumentLockStatus.ts) queries payload-locked-documents with document.value: { in: ids }. document is a polymorphic relationship to every collection, so the SQL adapters compare the ids against one column per collection and bind collections × ids parameters. D1 allows 100 bound parameters, so with around 15 collections the limit is reached at about 7 documents. Related: #17493, #14766 (limitedBoundParameters only covers id queries).

Link to the code that reproduces this issue

https://github.com/digitalwerber/payload/blob/fix/bulk-delete-lock-cleanup-d1/test/locked-documents/bulk-delete.int.spec.ts (test added on this branch)

Reproduction Steps

  1. Use @payloadcms/db-d1-sqlite with a config of ~15 collections.
  2. Create 7 documents in one collection.
  3. Select all 7 in the list view and delete them: the request fails with "too many SQL variables".

Which area(s) are affected?

area: core, db: d1-sqlite

Environment Info

payload: 4.0.0-beta.6
@payloadcms/ui: 4.0.0-beta.6
@payloadcms/db-d1-sqlite: 4.0.0-beta.6
next: 16.4.2
node: 24.22.1

Activity

  1. added
    area: core
    db: d1-sqlite
    on Oct 30, 2026
  2. Tthanh2k6 commented on Oct 31, 2026

    @Tthanh2k6

    Ran into this exact Cloudflare D1 variable ceiling (SQLITE_MAX_VARIABLE_NUMBER = 100, vs standard SQLite's 999/32766) during bulk deletes, when the payload_locked_documents_rels cleanup expands inArray parameters across every relation column at once.

    Until @payloadcms/db-d1 chunks that internal locked-document query natively, you can unblock production deletes without patching node_modules by batching IDs in a custom endpoint or hook:

    const safeChunkSize = Math.max(1, Math.floor(90 / (relationSlugs.length + 2)));

    Running sequential payload.delete({ collection, where: { id: { in: chunk } } }) calls of safeChunkSize keeps the generated WHERE (... OR ...) bind count under D1's 100-parameter limit across all relation joins.

  3. self-assigned this
    on Nov 2, 2026
  4. digitalwerber commented on Nov 14, 2026

    @digitalwerber
    Author

    Hi @r1tsuu, a quick process question, since you're assigned to most of the issues I reported recently (#19232, #19233, #19242, #19251).

    For each of them I opened a PR with a failing test and a fix (#19235, #19243, #19252, plus #19237 for #19234). None of them has had a review yet, which is fine - I'd just like to know how to report bugs in a way that's most useful to you:

    1. Are PRs from reporters for v4 beta bugs helpful, or do you prefer to fix them yourselves and only get a minimal reproduction (failing test) from me?
    2. If PRs are welcome: is there anything that would make them easier to review or land (scope, test location, separate PRs per adapter, etc.)?

    Either way works for me; I patch locally in the meantime. I'd just rather not flood you with PRs you don't need, and equally not hold back ones that would actually help.

    Thanks for all the work you're putting into v4!

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

Metadata

Metadata

Assignees

Labels

BugPayload OSSarea: coredb: d1-sqlite

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions