Repository navigation
fix(schema): remove a map that lives under a nested path - #16461
Merged
vkarpov15 merged 3 commits intoAug 21, 2026
Merged
Conversation
Schema#remove() walks the subpaths of a nested branch and calls _deletePath on each. A map registers its values under `<path>.$*`, which has no branch of its own in the tree, and by the time that subpath is reached its parent has already been deleted in the same pass, so the walk lands on undefined and the delete throws. _deletePath now stops when a piece along the way is missing, and the nested branch filters mapPaths the way the flat branch already does, so the schema stops answering pathType() for a path it removed. Follow up to Automattic#16457, which covered the flat case.
Removed commented-out code explaining mapPaths behavior.
Removed commented code regarding synthetic subpaths.
vkarpov15
added a commit
that referenced
this pull request
Aug 21, 2026
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.
Follow up to #16457, which covered the flat case. The nested branch of
Schema#remove()has the same two problems, and one of them throws:A map registers its values under
<path>.$*inpaths, so the nested branch walks['n.m', 'n.m.$*']and calls_deletePathon each._deletePathwalksschema.treedown the pieces, and by the time it gets ton.m.$*the parenttree.n.mhas already been deleted by the previous iteration, sobranchisundefinedand thedeletethrows.$*has no branch of its own in the tree in any case.So
_deletePathnow stops when a piece along the way is missing. Nothing to delete is not an error there.With that out of the way the second problem shows: the nested branch never filtered
mapPaths, which is what the flat branch does. Measured afterschema.remove('n'), before and after:pathsmapPathspathType('n.m')['_id']['n.m.$*']real['_id'][]adhocOrUndefinedSo the schema kept answering for a path it had just removed, which is the same thing #16457 described, only reached through a nested parent. Both branches now do the same cleanup.
Test in the
remove()block. It fails onmasteron the first assertion, sinceremovethrows before the rest runs.test/schema.test.jspasses 225. Fullnpm testhere matches master, the only failure being aneachAsynctimeout that reproduces on a clean checkout on this machine.eslintis clean.