fix(ui): resolve globals correctly in copyDataFromLocale#16334
Open
robinvandenb wants to merge 1 commit intopayloadcms:mainfrom
Open
fix(ui): resolve globals correctly in copyDataFromLocale#16334robinvandenb wants to merge 1 commit intopayloadcms:mainfrom
robinvandenb wants to merge 1 commit intopayloadcms:mainfrom
Conversation
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.
The bug
Calling the server function
copyDataFromLocaleHandlerwith aglobalSlug(triggered by the admin UI's "Copy to locale" button on any Global) crashes with:The same button works fine for Collections. For Globals it is 100% broken. Reproducible on current
mainand released versions up to at leastv3.83.0.Repro steps
localizationenabled and ≥ 2 locales, define a Global (e.g.{ slug: 'homescreen-layout', fields: [...] }).Root cause
copyDataFromLocaledestructuredglobalsoffreq.payloadand then looked upglobals[globalSlug].config.fields, assumingpayload.globalsis a slug-keyed map the waypayload.collectionsis. It isn't. Perpackages/payload/src/index.ts,payload.globalsalways has shape{ config: SanitizedGlobalConfig[] }. Every other place in the codebase (e.g.packages/payload/src/globals/operations/local/findOne.ts,update.ts,restoreVersion.ts,findVersions.ts,findVersionByID.ts,countVersions.ts,utilities/handleEndpoints.ts,utilities/getRequestEntity.ts) resolves a global viapayload.globals.config.find((c) => c.slug === globalSlug).copyDataFromLocalewas the only offender, soglobals[globalSlug]was alwaysundefinedfor a real slug and.configthrew.The fix
payload.globals.config.find((c) => c.slug === globalSlug), matching the rest of Payload.APIError("The global with slug X can't be found.", 404)if the slug is missing (mirrored the same guard on the collection branch so a badcollectionSlugno longer crashes onundefined.config.fieldseither).globalsdestructure.Public signatures of
copyDataFromLocale/copyDataFromLocaleHandlerare unchanged.Tests
Added under
test/localization/int.spec.ts, inside the existingCopying To Localeblock:copies undefined fields from a source locale to a target locale on a global— seedsen, clearses, callscopyDataFromLocaleHandlerwithglobalSlug, assertstitleandgroup.subtitleare copied on theesdraft. This would have failed onmainwith the originalTypeError.throws a clear error when the global slug does not exist— asserts the newAPIErrorpath.Introduced a minimal
localized-global-for-copyglobal intest/localization/config.tsfor the round-trip.Run locally with: