fix: polymorphic relationship returns null when target is trashed#16403
Open
KibbeWater wants to merge 5 commits intopayloadcms:mainfrom
Open
fix: polymorphic relationship returns null when target is trashed#16403KibbeWater wants to merge 5 commits intopayloadcms:mainfrom
KibbeWater wants to merge 5 commits intopayloadcms:mainfrom
Conversation
Author
|
@denolfe This PR targets at main but would likely benefit being added to 3.x as well. Would you like me to open a separate PR and just cherry-pick the commits over? |
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?
Polymorphic single relationships to a trashed document return
nullinstead of{ relationTo, value: null }. Single relationships to atrash: truecollection are also nullable in generated types regardless ofrequired.Why?
The runtime emitted a shape the types said was impossible.
typeof reference.value === 'object' && reference.value.slugtypechecked but crashed on trashed targets —typeof null === 'object'.#16102 set "for single relationships, the field is set to null" but implemented it for non-polymorphic only. Polymorphic single (and localized polymorphic single) were missed. The schema widening covers
required: truerels to trashable collections, where the runtime nulls the field but the type used to forbid it.How?
relationshipPopulationPromise.ts): null the whole wrapper, not justwrapper.value, when the populated value isnull. Covers single polymorphic and localized polymorphic single. PolymorphichasMany was already filtered.
configToJSONSchema.ts): widen single rels totrash: truetargets toT | nullregardless ofrequired.payload-locked-documents.userandpayload-preferences.userwiden automatically.reference.valueinCMSLink(3 templates, 2 examples).Pages; five integration tests;payload-types.tsregenerated.