Skip to content

Fix Delta._do_iterable_opcodes overwriting parent container for nested tuples - #680

Open
X6M-Work wants to merge 1 commit into
qlustered:masterfrom
X6M-Work:fix-delta-nested-tuple-opcodes
Open

X6M-Work wants to merge 1 commit into
qlustered:masterfrom
X6M-Work:fix-delta-nested-tuple-opcodes

Conversation

@X6M-Work

Copy link
Copy Markdown

Summary

Applying a Delta with _iterable_opcodes to a nested tuple overwrote the enclosing parent container instead of updating the tuple element inside it.

Root cause

In deepdiff/delta.py, _get_elements_and_details(path) returns (elements, parent, parent_to_obj_elem, parent_to_obj_action, obj, elem, action) where obj is the container holding the target element and parent is one level above obj. _do_iterable_opcodes wrote the rebuilt tuple back to parent using parent_to_obj_elem/parent_to_obj_action, which only worked when path == "root" (parent is None) and replaced the parent container for any nested path like root['a'].

Solution

  • Keep target_parent, target_elem, and target_action pointing to (self, 'root', GETATTR) when parent is None, and to (obj, elem, action) otherwise.
  • Add regression coverage in tests/test_delta.py for single- and two-level nested tuples.

Verification

  • pytest tests/test_delta.py -q: 129 passed (1 unrelated failure in test_delta_repr due to orjson not installed locally).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant