Skip to content

fix(content-releases): await release cleanup inside its try/catch - #27893

Merged
innerdvations merged 6 commits into
strapi:developfrom
irontaek:fix/content-releases-await-cleanup
Oct 15, 2026
Merged

innerdvations merged 6 commits into
strapi:developfrom
irontaek:fix/content-releases-await-cleanup

Conversation

@irontaek

@irontaek irontaek commented Oct 1, 2026 •

Copy link
Copy Markdown

What does it do?

Awaits release-action cleanup and each nested updateReleaseStatus call in document delete/update middleware and the afterDeleteMany lifecycle. Failures now reach the existing error handlers, while document operations retain their results.

Passes the bootstrap Strapi instance into the middleware and cleanup helpers. Regression tests use injected dependencies and typed document contexts instead of global.strapi or any.

Why is it needed?

Calling an async cleanup helper without awaiting it lets its rejection escape the surrounding try/catch. Awaiting only the outer helper is also insufficient when its release-status updates are not awaited: a failed status query still becomes an unhandled rejection.

How to test it?

From packages/core/content-releases, run yarn jest --runInBand.

The 12 cleanup tests exercise the actual middleware and lifecycle registered by bootstrap. They cover lookup, cleanup, and status-update failures on all three paths, plus successful updates of all affected releases. Removing the three nested awaits makes exactly the three status-failure tests fail; restoring them passes all 12.

Validated locally with Node 22.14.0:

  • Content-releases server tests: 110 passed, 3 skipped.
  • Content-releases server type check and lint for all changed files: passed.
  • Monorepo build (37 projects): passed.
  • Full frontend tests (12 projects), type checks (38 projects), lint (39 projects), and Prettier checks: passed.
  • Full unit run: all projects except draft-release passed. That unchanged package failed because Node 22.14.0 did not load .ts files directly; NODE_OPTIONS=--experimental-strip-types yarn nx run draft-release:test:unit passed.
  • E2E coverage remains for CI.

Related issue(s)/PR(s)

Fixes CPR-495

The document middlewares and the afterDeleteMany lifecycle wrap the
release-action cleanup in try/catch to log failures without blocking the
delete or update, but they called the async helpers without await. The
catch never ran, so a failure became an unhandled rejection instead of
the logged error.
@github-actions github-actions Bot added the community Changes and fixes created by community members label Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to our community triage board as CPR-495.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adds await to async cleanup calls in content release handlers.

The PR is not safe to merge until nested release-status rejections are handled and the repository requirements for tests and fixtures are met.

Fix All in Claude CodeFindings

  1. P1 Status update rejections escape ▶
  2. P2 Lifecycle regression test missing ▶
  3. P2 Test assigns global Strapi ▶
  4. P2 Test contexts use any ▶
Fix with agent prompt
### Issue 1
packages/core/content-releases/server/src/middlewares/documents.ts:82
When `updateReleaseStatus` rejects because an action-count or status query fails, this new `await` does not bring the rejection into the surrounding `catch`. The cleanup helper calls `updateReleaseStatus` without awaiting it. The update middleware and `afterDeleteMany` helper have the same gap, so a failure can still become an unhandled rejection instead of being logged. Await the status updates within each helper.

### Issue 2
packages/core/content-releases/server/src/bootstrap.ts:51
The new tests cover failures in the two document middlewares but do not exercise this `afterDeleteMany` call. If its `await` were removed, these tests would not catch the return of an unhandled rejection. The repository requires regression tests for bug fixes; add a failure-path test for this lifecycle before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 3
packages/core/content-releases/server/src/middlewares/__tests__/documents.test.ts:9
This fixture assigns `global.strapi` instead of supplying the dependency directly. The repository guide says never to use `global.strapi` and to prefer dependency injection. Refactor the fixture and, if needed, the middleware boundary to meet that requirement before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

### Issue 4
packages/core/content-releases/server/src/middlewares/__tests__/documents.test.ts:27
Both new tests cast their middleware contexts to `any`, although a document-middleware context type is available. The repository guide prohibits `any` when a type can reasonably be defined. Use typed contexts or a narrowly typed fixture before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR awaits three release-action cleanup calls so their rejected promises reach existing error handlers, and adds regression tests for the two document middlewares.

  • Rejections from the nested, unawaited release-status updates can still escape those handlers.
  • The lifecycle change lacks a regression test, and the new test fixture conflicts with repository guidance on globals and typing.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Document update/delete or afterDeleteMany] --> B[Await cleanup helper]
  B --> C[Query and change release actions]
  C --> D[Call updateReleaseStatus without awaiting]
  B -- helper rejection --> E[Existing catch logs error]
  D -- asynchronous rejection --> F[Rejection bypasses catch]
Loading

Reviews (1) · Last reviewed commit: "fix(content-releases): await release cle..."

@innerdvations innerdvations added source: core:content-releases Source is the Content Releases feature pr: fix This PR is fixing a bug qa-done Applied when a PR passes QA labels Oct 12, 2026
@innerdvations innerdvations added this to the 5.57.1 milestone Oct 12, 2026
@draft-release draft-release Bot modified the milestones: 5.58.0, 5.58.1 Oct 12, 2026
Keep the locale filter from strapi#28023 and await release-action cleanup so
status failures are logged instead of becoming unhandled rejections.
@github-actions github-actions Bot removed the qa-done Applied when a PR passes QA label Oct 15, 2026
@innerdvations innerdvations added the needs-qa generates AI QA checklist label Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI-generated QA checklist

Scope / Impact

fix(content-releases): await release cleanup inside its try/catch by @irontaek -> develop.

Three fire-and-forget calls become awaited, plus one signature change:

  • middlewares/documents.ts:67 and :83 - await ...updateReleaseStatus(release.id) inside the per-release loops.
  • middlewares/documents.ts:106 / :138 - await the cleanup helper itself, so rejections land in the existing try/catch.
  • bootstrap.ts:28 / :54 - same two fixes for the afterDeleteMany DB lifecycle; deleteReleasesActionsAndUpdateReleaseStatus now takes strapi explicitly instead of reading the global.

Affected: Content Releases (EE-only, gated on cms-content-releases) status recomputation (ready / blocked / empty); Content Manager document update and delete via updateActionsOnUpdate / deleteActionsOnDelete; i18n locale deletion and anything else hitting db.deleteMany on a draft-and-publish collection type.

Two consequences to watch:

  1. Timing - release status is now correct the moment the update/delete response returns (previously a race, so a stale badge was possible). Conversely, save/delete now waits on N x (2 counts + 1 update) queries, one release at a time - a latency increase for documents in many releases.
  2. Error handling - a DB failure during status recomputation used to escape as an unhandled rejection (can terminate the Node process). It is now caught, logged, and the document operation still returns its result.

middlewares/__tests__/documents.test.ts adds 12 cases driving the real bootstrap()-registered middleware/lifecycle with an injected mock strapi.

Manual QA

  • On EE, add an entry of a draft-and-publish collection type to a release, then update it in the Content Manager. The release status badge must reflect the new validity immediately, with no manual refresh or delay.
  • Make that entry invalid (clear a required field) while it is in a release and save. The release must flip to blocked as soon as the save completes.
  • Delete an entry belonging to one or more releases. The entry deletes, its release actions disappear, and every affected release is recomputed - a release left with zero actions must go to empty, not stay ready/blocked.
  • Put the same document into 3+ unreleased releases, then update it once. Confirm all are recomputed (this is the loop the await was added to), and note whether the save feels slower than on develop.
  • Locale delete (afterDeleteMany): with i18n enabled, add localized entries to a release, then delete that locale in Settings > Internationalization. Actions for that locale are removed, statuses update, and the locale deletion completes without error.
  • Failure is logged, not fatal: force a DB failure during cleanup (lock/stop the DB mid-operation, or temporarily throw inside updateReleaseStatus). The update/delete still succeeds, the matching Error while ... release actions after update|delete|entry deleteMany line is logged, and the Strapi process does not crash.
  • Regression: publish / unpublish / discard draft / clone on a released entry - untouched by the diff but sharing the middleware chain.
  • Regression: Releases list, release detail, "ready to publish" filtering, and publishing a release end to end.

Edge Cases

  • Document in zero releases - findMany returns [], loop never runs; no behavior or latency regression.
  • Bulk delete of many entries, and locale delete over a large dataset - the awaited sequential loop is now in the request critical path; watch for timeouts.
  • Already-published release (releasedAt set) - the update path filters on releasedAt: null, so a published release must not be mutated by a later edit of a formerly-included entry.
  • Locale variants on delete: '*', explicit locale, array of locales, and omitted (falls back to default locale) - getDeletedLocalesFilter decides which actions get cleaned up.
  • Non-draft-and-publish content and single types - middlewares bail early; confirm untouched.
  • CE / no EE license - all of bootstrap is behind strapi.ee.features.isEnabled('cms-content-releases'); confirm no errors and no change to update/delete.
  • Databases: SQLite plus PostgreSQL or MySQL. Cleanup queries now complete before the response - check for lock contention under concurrent updates to entries in the same release.
  • Scheduled releases - scheduling (syncFromDatabase) and scheduled publish unaffected.
  • An editor without release-management permissions updating/deleting an entry that is in a release must still succeed (cleanup runs server-side).

Test Setup

  • EE license required (cms-content-releases); run examples/getstarted with STRAPI_LICENSE, use IS_EE=true / RUN_EE=true for front/E2E.
  • A collection type with draftAndPublish: true and at least one required field, to toggle entry validity -> blocked.
  • i18n enabled with 2+ locales and a localized collection type, for the afterDeleteMany path.
  • 3+ unreleased releases sharing one document, plus 1 already-published release.
  • SQLite plus docker-compose -f docker-compose.dev.yml up -d and DB=postgres yarn develop.
  • Unit: yarn jest --runInBand from packages/core/content-releases.

Possible QA Automation

Candidate Test Layer Priority Signal
Release status correct in the response immediately after a document update/delete (no polling) API Integration Recommended Directly asserts the race this PR closes; the new unit tests mock the DB and cannot prove real ordering
All releases containing a document are recomputed on update (3+ releases) Unit (added) Recommended Covers the for loop via the updateStatus.mock.calls assertion
Locale deletion clears release actions and recomputes status API Integration Recommended afterDeleteMany is only reachable through db.deleteMany, not the Document Service - thinnest-covered of the three paths
Cleanup failure logs without rejecting the document operation, all three paths Unit (added) Recommended Removing the three awaits fails exactly the three status cases
Published release (releasedAt set) not mutated by a later entry edit API Integration Optional Filter boundary not covered by the new mocks
Releases badge updates without refresh after editing an entry E2E Optional Closest to the user-visible symptom; needs RUN_EE=true
Save/delete latency for a document in many releases API Integration Optional Guards the sequential-await cost this fix introduces

Assumptions / Gaps

  • The PR references CPR-495 (internal ticket) but not the user-visible symptom, so the impact above is inferred from the code: stale release status and/or an unhandled rejection on DB errors during cleanup. Worth confirming against the ticket.
  • No reproduction steps for the original failure. It needs a DB error during updateReleaseStatus, hard to trigger organically - manual verification of that path likely needs temporary fault injection.
  • Latency is unquantified. updateReleaseStatus runs two countActions queries plus one update per release, now awaited sequentially inside the request. No benchmark included; a sanity check on a realistic dataset is worthwhile. (Parallelising the loop is the natural follow-up, out of scope here.)
  • The new tests set global.strapi in beforeEach despite the PR body saying they avoid it, and middlewares/documents.ts still reads the global strapi - only bootstrap.ts was converted to explicit injection. Pre-existing pattern, not a regression; flagged so QA does not expect full DI on the middleware path.
  • No E2E test was added, so release-status UI timing is currently covered manually only.

QA Resolution

Add qa-done when completed, or qa-skipped if intentionally skipped.

…ails

A rejection in the awaited status loop skipped later releases. Catch each
refresh, continue, and rethrow the first error so the existing log still runs.
innerdvations
innerdvations previously approved these changes Oct 15, 2026

@innerdvations innerdvations 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.

Nice, thanks!

@innerdvations
innerdvations enabled auto-merge (squash) October 15, 2026 15:17
Look up allowed media kinds in a Set, and keep the empty attribute
default as a stable reference.
@innerdvations innerdvations added qa-done Applied when a PR passes QA and removed needs-qa generates AI QA checklist labels Oct 15, 2026
@innerdvations
innerdvations merged commit 415d3ba into strapi:develop Oct 15, 2026
105 of 107 checks passed
@draft-release draft-release Bot mentioned this pull request Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members pr: fix This PR is fixing a bug qa-done Applied when a PR passes QA source: core:content-releases Source is the Content Releases feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants