fix(core): return full entry object from invokeEvent instead of just data
#7667
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