Fix SaveAwareArgResolver ignored in nested mutations - #2784
Open
spawnia wants to merge 1 commit into
Open
Conversation
The default arg partitioner in ResolveNested unconditionally routed all arguments with resolvers into the post-save set. This meant SaveAwareArgResolver::runBeforeSave() was only honoured at the top level (where ModelMutationDirective explicitly passed the pre-save-aware partitioner) but silently ignored one level down inside nested HasMany/HasOne/ManyToMany/BelongsTo mutations. Collapse the two partitioner methods into one that always respects pre-save semantics. When root is not a Model, behavior is unchanged (all resolvers go to nested). When root is a Model, SaveAwareArgResolvers with runBeforeSave=true stay in the regular set so SaveModel can execute them before persisting.
There was a problem hiding this comment.
Pull request overview
Fixes a regression where SaveAwareArgResolver::runBeforeSave() was not honored inside nested model mutations, causing pre-save arg resolvers to run after child models were already persisted.
Changes:
- Make
ArgPartitioner::nestedArgResolvers()pre-save aware by default (and remove the redundantnestedArgResolversWithoutPreSave()variant). - Remove the explicit partitioner override from
ModelMutationDirective, relying on the corrected default behavior. - Add/extend integration test coverage for pre-save custom directives inside nested relations and add latitude/longitude test fields/columns.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/Execution/Arguments/ArgPartitioner.php |
Makes the default nested/regular argument partitioning honor SaveAwareArgResolver::runBeforeSave() for model roots and lifts pre-save resolvers out of @nest recursively. |
src/Schema/Directives/ModelMutationDirective.php |
Removes the now-unnecessary custom arg partitioner override when constructing ResolveNested. |
tests/Unit/Execution/Arguments/ArgPartitionerTest.php |
Updates unit tests to reflect the new default partitioning behavior and removes coverage for the deleted method. |
tests/Integration/Schema/Directives/CreateDirectiveTest.php |
Adds integration coverage demonstrating pre-save custom directive behavior in nested HasMany and deeper nested relations. |
tests/database/migrations/2018_02_28_000003_create_testbench_tasks_table.php |
Adds latitude/longitude columns to support new integration assertions. |
tests/database/migrations/2018_02_28_000004_create_testbench_posts_table.php |
Adds latitude/longitude columns to support deep relation integration assertions. |
tests/Utils/Models/Task.php |
Documents latitude/longitude properties for test model. |
tests/Utils/Models/Post.php |
Documents latitude/longitude properties for test model. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 a regression from #2777 (v6.69.0) where
SaveAwareArgResolver::runBeforeSave()was only honoured at the top level of a mutation. One level down inside nested HasMany/HasOne/ManyToMany/BelongsTo mutations, the pre-save resolver ran AFTER the child model was already persisted — silently discarding its attribute changes.The root cause:
ResolveNesteddefaulted to a partitioner that unconditionally routed all resolver-bearing args into the post-save set. OnlyModelMutationDirective::executeMutation()overrode this with the pre-save-aware variant; all 12 nested resolver call sites used the broken default.The fix collapses
nestedArgResolversWithoutPreSaveintonestedArgResolversso the correct behavior is the default everywhere. When root is not a Model, behavior is unchanged. When root is a Model,SaveAwareArgResolverinstances withrunBeforeSave=truestay in the regular set soSaveModelexecutes them before persisting. The now-redundant explicit partitioner inModelMutationDirectiveis removed.