Skip to content

fix(plugin-cloud-storage): do not re-apply upload edits when persisting adapter metadata - #18805

Open
AmineBenzaazaa wants to merge 1 commit into
payloadcms:mainfrom
AmineBenzaazaa:fix/18804-cloud-storage-upload-edits
Open

AmineBenzaazaa wants to merge 1 commit into
payloadcms:mainfrom
AmineBenzaazaa:fix/18804-cloud-storage-upload-edits

Conversation

@AmineBenzaazaa

Copy link
Copy Markdown

What?

plugin-cloud-storage no longer re-applies uploadEdits from the query string when it saves the metadata returned by an adapter's handleUpload (e.g. the suffixed filename from storage-vercel-blob with addRandomSuffix: true).

Why?

That metadata is saved with a nested payload.update({ req }) on the same req. req.file and req.payloadUploadSizes were cleared first, but req.query.uploadEdits was not. The nested update then read the focal point again (as query-string strings, so shouldReupload saw them as changed) and tried to re-fetch the file from the old, unsuffixed URL, which 404s and fails the create with a 500.

How?

Same thing the _payloadManagedCloudStorage branch of this hook already does: use a shallow copy of req.query without uploadEdits for the nested update and restore the original query afterwards.

Added a unit test in afterChange.spec.ts that checks the query seen by the nested update and that req.query is restored. It fails without the change and passes with it (vitest run --project unit packages/plugin-cloud-storage/src).

The same code is on 3.x (the reporter is on 3.90.2); happy to open a backport if you want one.

Fixes #18804

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: payloadcms/payload/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4abec8ae-e4d0-4f8b-ad10-0e0191a075b1
📥 Commits

Reviewing files that changed from the base of the PR and between 4d05bcd and 0ff1cb4.

📒 Files selected for processing: 2
  • packages/plugin-cloud-storage/src/hooks/afterChange.spec.ts
  • packages/plugin-cloud-storage/src/hooks/afterChange.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

The upload hook now removes uploadEdits from the request query during the nested metadata update. It restores the original query afterward. A test checks the nested update query and the restored request query.

Changes: Upload metadata update

Layer / File(s) Summary
Filter and restore the nested update query
packages/plugin-cloud-storage/src/hooks/afterChange.ts, packages/plugin-cloud-storage/src/hooks/afterChange.spec.ts
The hook removes uploadEdits from the query used for the nested metadata update, then restores the original query in finally. The test checks that the nested update receives only locale and that the original request retains uploadEdits.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 0ff1c

The metadata update no longer reprocesses upload edits, and no actionable merge-blocking risk is identified.

### Architecture Summary

Architecture risk: 🔵 Low · up to 0ff1c

The change affects 1 system.

Changed systems: packages/plugin-cloud-storage

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/plugin-cloud-storage (library) was modified; 2 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/plugin-cloud-storage/src/hooks/afterChange.spec.ts: Adds a test that captures the query passed to the nested metadata update during upload creation. It expects one update call, only locale in that call’s query, and both locale and uploadEdits in the original request query.
  • observed — Modified behavior in packages/plugin-cloud-storage/src/hooks/afterChange.ts: Before the nested metadata update, the hook now saves the original query, uses a copy without uploadEdits, and documents that reprocessing edits could trigger a re-upload from a stale file URL.
  • observed — Modified behavior in packages/plugin-cloud-storage/src/hooks/afterChange.ts: The finally block now restores the original request query after the nested update.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing uploadEdits from being re-applied when persisting adapter metadata.
Description check Passed The description directly explains the bug, the fix, the added test, and the expected behavior for plugin-cloud-storage.
Linked Issues check Passed Issue #18804 requires preventing uploadEdits from being re-applied during the nested metadata update after handleUpload. The PR copies req.query, removes uploadEdits for that update, and resto…
Out of Scope Changes check Passed The reported changes are limited to the afterChange fix and its unit test. Both changes directly support issue #18804. No unrelated change is identified in the supplied whole-PR summary.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check

Explanation

Issue #18804 requires preventing uploadEdits from being re-applied during the nested metadata update after handleUpload. The PR copies req.query, removes uploadEdits for that update, and restores the original query in finally. The added afterChange.spec.ts test checks the nested query and query restoration. The supplied evidence also reports that the test fails without the change and passes with it.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

plugin-cloud-storage: upload with a focal point set before first save fails when the adapter returns a new filename (e.g. Vercel Blob addRandomSuffix)

1 participant