Skip to content

feat(push): handle deleting custom types that still have documents#187

Open
jomifepe wants to merge 6 commits into
mainfrom
jp/delete-ct
Open

feat(push): handle deleting custom types that still have documents#187
jomifepe wants to merge 6 commits into
mainfrom
jp/delete-ct

Conversation

@jomifepe
Copy link
Copy Markdown
Contributor

@jomifepe jomifepe commented May 18, 2026

Summary

  • Detect Custom Types API 400 responses when deleting a type that still has documents (BadRequestError + stable checks on the response body).
  • Resolve document counts via POST …/core/documents/search (Editor parity: customTypes + limit: 0), enforce the 200 bulk-delete limit, then call DELETE …/core/documents with customtype_ids before retrying type deletion.
  • --delete-pages opts in to cascading deletion of associated pages when push would otherwise stop with an error; --force alone does not enable that path (it still only skips dirty-repo checks and the “would delete remote models” guard).
  • Errors include a deep link to the filtered builder working view: https://{repository}.{host}/builder/working?customTypes={id}.

Note

Medium Risk
Adds automated bulk deletion of documents during prismic push when removing a custom type, which is potentially destructive and depends on new API calls and 400-error detection; guarded by an explicit --delete-pages flag and a hard 200-document limit.

Overview
prismic push now detects when a custom type deletion fails because it still has associated documents, and surfaces clearer guidance (including a deep link to the filtered working view).

When this condition is hit, it queries the document total via POST core/documents/search, enforces a 200-document bulk-delete cap, and—only with --delete-pages—cascades by calling DELETE core/documents before retrying the type deletion.

The request layer now throws a dedicated BadRequestError on HTTP 400 to support stable detection of the “documents in use” failure mode.

Reviewed by Cursor Bugbot for commit 86370a7. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/commands/push.ts Outdated
Comment thread src/lib/request.ts
Comment thread src/commands/push.ts
@jomifepe jomifepe self-assigned this May 18, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 86370a7. Configure here.

Comment thread src/lib/request.ts

constructor(response: Response, body: unknown) {
super(response);
this.body = body;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

BadRequestError body property is set but never read

Low Severity

The body property on BadRequestError is assigned in the constructor but never read anywhere in the codebase. The isDocumentsInUseError function — the only consumer of BadRequestError — calls error.text() (re-reading the response) instead of accessing error.body. This makes body dead code that adds confusion about the intended API.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 86370a7. Configure here.

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.

1 participant