Skip to content

Deepcopy new values when applying a Delta - #678

Open
tony1233200 wants to merge 1 commit into
qlustered:devfrom
tony1233200:fix/655-delta-deepcopy-new-values
Open

tony1233200 wants to merge 1 commit into
qlustered:devfrom
tony1233200:fix/655-delta-deepcopy-new-values

Conversation

@tony1233200

Copy link
Copy Markdown

Fixes #655.

Applying the same Delta to separate objects with the default
mutate=False put the same mutable value into every result: editing
one result changed the others and corrupted the values used by later
applications of that Delta.

Delta.__add__ already deepcopies the input object, but the values
taken from the stored diff were inserted by reference:
_do_item_added and _do_values_or_type_changed both pass
new_value straight from self.diff into _set_new_value, which
stored it as-is.

Fix (in deepdiff/delta.py, deepcopy is already imported):

  • in _set_new_value, deepcopy new_value before storing it. This
    covers dictionary_item_added, iterable_item_added,
    attribute_added, values_changed and type_changes in one place.
  • in _do_iterable_opcodes, deepcopy opcode.new_values when
    extending transformed for replace / insert tags (the equal
    tag copies from the already-deepcopied root and needs no change).

Verification:

Out of scope, noted for follow-up: _do_set_or_frozenset_item builds
a new set but its members are still the diff's objects.

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