Repository navigation
fix: isolate locale properties in createLocalReq - #18280
Open
Dextheking1 wants to merge 2 commits into
Open
Dextheking1 wants to merge 2 commits into
Dextheking1 wants to merge 2 commits into
Conversation
Fixes payloadcms#18246. A Local API call that passes both `req` and a different `locale` rewrote the caller's `req.locale`/`req.fallbackLocale` in place. `beforeChange` merges submitted data into per-locale fields based on `req.locale` after hooks/validation have awaited, so the nested call's locale corrupted the parent operation's data (submitted values merged into the wrong locale). Wrap the incoming req with `isolateObjectProperty(req, ['locale', 'fallbackLocale'])` (the same pattern `restoreVersion` already uses) so the nested operation sees its own locale through the returned request while the caller's object keeps its original values.
Dextheking1
marked this pull request as ready for review
September 24, 2026 16:33
Contributor
Author
|
Rebased onto current main. Upstream consolidated |
This branch has not been deployed
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.
Fixes #18246.
Problem
A Local API call made inside a field
validate, a relationshipfilterOptions, or abeforeChangehook normally passes the operation'sreq. If that call also passes alocaledifferent from the operation's,createLocalReqwrote that locale (and the recomputedfallbackLocale) onto the caller'sreqobject.beforeChangemerges submitted single-locale data into the per-locale document in deferredmergeLocaleActionsthat readreq.localeafter every field's hooks/validation have awaited, so the submitted values were merged into the nested call's locale instead of the operation's, silently corrupting localized data (see the issue'sen/esrepro).Root cause
createLocalReq(packages/payload/src/utilities/createLocalReq.ts) assignedreq.locale/req.fallbackLocaledirectly on the passed-in object.Fix
Wrap the incoming
reqwithisolateObjectProperty(req, ['locale', 'fallbackLocale']), the same patternrestoreVersionalready uses (option 1 from the issue). The nested operation still sees its own locale through the returned request; the caller's object keeps its original values. All other callers use the return value, so no side-effect behavior changes.Testing
createLocalReq - locale isolationsuite inpackages/payload/src/utilities/createLocalReq.spec.ts:localedoes not rewrite the caller'sreq.locale(returned request carries the nested locale)req.fallbackLocaleis not rewrittenreq.localeisolateObjectProperty.spec.ts+createLocalReq.spec.ts: 18 passed.tsc --noEmitonpackages/payload: no new errors (104 pre-existing TS6305 project-reference errors on baseline and with the change).