fix(plugin-cloud-storage): pass req to find in getFilePrefix for transaction support#16172
Open
Gdhanush-13 wants to merge 1 commit intopayloadcms:mainfrom
Open
Conversation
…saction support During a create operation, getFilePrefix queries the database for the document's prefix. Without passing req, the query runs outside the current transaction and cannot see the uncommitted document, causing the prefix to resolve to an empty string. This leads to: - 'Failed to persist upload data' warning in afterChange hook - 404 when fetching /api/<collection>/file/<filename> - Crop/edit flow failing during initial upload Passing req ensures the find operation participates in the same transaction context, allowing it to see the just-created document. Fixes payloadcms#15989
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #15989 -
getFilePrefixreturns empty prefix during create transaction, causing crop/save flow to fail withFailed to persist upload data.Root Cause
In
packages/plugin-cloud-storage/src/utilities/getFilePrefix.ts, thereq.payload.find()call on line 42 does not passreq. During a create operation, the document is being created within a transaction. Withoutreq, the find query runs outside the transaction context and cannot see the uncommitted document, so it returns no results and the prefix resolves to an empty string''.Symptoms (as reported)
Failed to persist upload data for collection ...(warning in afterChange)GET /api/media/file/<filename>returns 404Fix
Added
reqto thefind()call so the query participates in the same transaction and can see the just-created document:const files = await req.payload.find({ collection: collection.slug, depth: 0, draft: true, limit: 1, pagination: false, + req, where: {