fix(core): return full entry object from invokeEvent instead of just data#7667
Open
adbw-pge wants to merge 2 commits intodecaporg:mainfrom
Open
fix(core): return full entry object from invokeEvent instead of just data#7667adbw-pge wants to merge 2 commits intodecaporg:mainfrom
data#7667adbw-pge wants to merge 2 commits intodecaporg:mainfrom
Conversation
…data
The `invokeEvent` function in registry.js was returning only the data
payload (`_data.entry.get('data')`) instead of returning the complete
entry object. This caused entry metadata fields (slug, path, meta, etc.)
to be lost during event processing, particularly affecting file
collections that rely on slug for file lookups.
When `invokePreSaveEvent` was called during entry persistence:
1. Entry starts with all metadata: slug, path, meta, isModification, etc.
2. `invokeEvent` is called with the full entry object
3. `invokeEvent` returns ONLY the data payload, stripping metadata
4. Calling code replaces the full entry with just the data payload
5. Downstream operations like `entryToRaw` receive incomplete entry
6. `fieldsOrder` method fails trying to match slug to file definitions
This manifested as errors like:
- "No file found for undefined in [collection]"
- "TypeError: can't access property 'toJS', file is undefined"
The bug was introduced in commit 0d7e36b (January 31, 2020) and has
existed for ~5 years, but was only exposed in recent versions (3.2.0+)
when file collection persistence logic started calling `invokePreSaveEvent`
and fully relying on its return value to update the entry draft.
Changed `invokeEvent` to return `_data.entry` (the complete entry object)
instead of `_data.entry.get('data')` (just the data payload).
This preserves all entry metadata through the event handler chain, ensuring
that callers like `invokePreSaveEvent` receive the complete entry object
with all properties intact.
Verified fix resolves file collection publishing issues where:
- Custom widgets modify entry data during save
- File collections with single files rely on slug matching
- Entry metadata must be preserved through preSave event handlers
Fixes #[issue-number-if-exists]
fix(core): test returning full entry when invoking preSave handler
Contributor
yanthomasdev
left a comment
There was a problem hiding this comment.
Thanks @adbw-pge, I believe your changes are correct and appreciate the PR. I'm not super familiar with this code path so I'll let @martinjagodic know to make the final call/review here.
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.
Hello,
I hope this message finds you well.
I ran across a little bug while trying to upload some files using my custom component.
Summary
For the sake of simplicity, I created a reproduction of the bug in the form of a test:
bug.patch
What happens is: when trying to update a file in a collection, moving the draft version to the stored versions loses some of the necessary metadata in the transfer, which results in a
slugproperty access that throws.The goal of the patch file here is to prove the existence of the bug. You may re-use this same patch file to «before and after» my commit gets applied:
it’ll fail in the first case, after running through a dedicated case block:
and succeed when run on my fix commit.
A more detailed view:
From the Commit message (which, you’ll forgive me, was written by an AI gremlin):
The
invokeEventfunction in registry.js was returning only the data payload (_data.entry.get('data')) instead of returning the complete entry object. This caused entry metadata fields (slug, path, meta, etc.) to be lost during event processing, particularly affecting file collections that rely on slug for file lookups.When
invokePreSaveEventwas called during entry persistence:invokeEventis called with the full entry objectinvokeEventreturns ONLY the data payload, stripping metadataentryToRawreceive incomplete entryfieldsOrdermethod fails trying to match slug to file definitionsThis manifested as errors like:
I suspect that the bug bug was introduced in commit 0d7e36b (January 31, 2020) and has existed for ~5 years, but was only exposed in recent versions (3.2.0+) when file collection persistence logic started calling
invokePreSaveEventand fully relying on its return value to update the entry draft - I’m not totally sure, though.I changed
invokeEventto return_data.entry(the complete entry object) instead of_data.entry.get('data')(just the data payload).This preserves all entry metadata through the event handler chain, ensuring that callers like
invokePreSaveEventreceive the complete entry object with all properties intact.Verified fix resolves file collection publishing issues where:
fix(core): test returning full entry when invoking preSave handler
Test plan
For the testing,
registry.spec.jsso that it checks that all necessary metadata gets preserved.backend.spec.jsthat checks that slug metadata gets preserved when callingpersistEntry().These tests do not reproduce the whole scenario that is demonstrated in the
bug.patchfile, though. I dunno whether it would be pertinent to include it in the PR though. Let me know.Checklist
Thank you for considering my PR, looking forward to your response,
Anthony