Repository navigation
Fix /schema/apply dropping a collection when its first diff entry is a nested meta delete - #27880
Conversation
c375176 to
5702a70
Compare
ComfortablyCoding
left a comment
There was a problem hiding this comment.
Thanks for the PR!
This partially addresses the issue but looks to miss the following cases:
- Adding a meta property to an existing collection is treated as creating a new collection.
- For
Dcases (and potentiallyN), all field/relation changes are dropped before apply runs. - Slightly outside the current scope but should be addressed: Adding or removing a meta property on a relation has the same issues.
|
good catch, all three were real. the field/relation drop was get-snapshot-diff's deletedCollections filter, same unguarded kind check. guarded it there. collection creation now skips nested meta adds, and relations got the same three guards fields already had. added a test for each, all four fail on main. thanks for merging main in. |
bf616dd to
88d8ec3
Compare
|
Reporter of #27877 here. I went back over this against current The three review points are addressed in the diff. Mapping each to the code it touches:
One thing changed after the review was written. v12.2.0 introduced // `deep-diff` reports a whole-entity deletion as a root-level `D` (i.e. no `path`)
return change.path !== undefined;A nested-meta Still reproducible: Happy to test a build against a real schema with a few hundred custom collections if that would be useful. (For the record: #28030 covered the same ground and was closed shortly after it opened.) |
ComfortablyCoding
left a comment
There was a problem hiding this comment.
Thanks for the updates, I believe their are still some gaps present, for example:
New grouped collection is dropped if nested change is present in parent
- Create parent collection
parentand generate snapshot - Adjust generated snapshot to have a:
- a new property to
parent.meta - a new collection named
child
- Build diff based on the adjusted snapshot
- Apply snapshot, observe child is not actually created
Let's improve test coverage here, given the missing edge cases seems we do still have gaps.
|
good catch on the parent meta update, guarded \parentWillBeCreatedInThisApply\ with !isNestedMetaUpdate\ so nested changes on an existing parent don't cause new grouped children to be skipped, and added a test covering that case. all 25 apply-diff unit tests pass. |
Nitwel
left a comment
There was a problem hiding this comment.
Instead of having a isNestedMetaUpdate, could we maybe look into fixing this a step before, just after the diff generation, so that the final diff reflects 100% on what changes will actually be made?
|
Good point. Refactored away from
Added Updated |
4b96fbf to
d5b433c
Compare
Nitwel
left a comment
There was a problem hiding this comment.
As I said before, please move your changes to before the actual applying logic so that when we start applying the diff, it is the final diff and the changes reflect 1:1 on what is gonna be changed.
|
Thanks for clarifying. I’ve moved the fix into diff generation, removed the apply-time changes, and added regression tests for the cases raised. Please let me know if I’ve missed anything. |
Nitwel
left a comment
There was a problem hiding this comment.
Added e2e tests, but finally looks good to me! Thanks for the work.
|
Thanks for the guidance @Nitwel, appreciate the reviews and support.❤️ |
What's Changed
Fixes #27877
Nested additions and removals inside
metawere emitted bydeep-diffasNorD. Since schema apply uses the first diff kind to choose between create, update, and delete, those property changes could be mistaken for whole-entity operations.This now gets normalized in
getSnapshotDiff, before the diff reaches validation or apply:Echange atmetaNandDremain unchanged for actual entity creation and deletionTests
Added regression coverage for:
Checklist
@directus/specs)@directus/sdk) updated to reflect the changes