patch() inserts mutable values from a diff directly into the destination. Mutating the patched result then changes the diff and affects subsequent applications, even with the default in_place=False. This occurs for both added and replaced values.
from dictdiffer import diff, patch
changes = list(diff({}, {"value": {"items": [1]}}))
result = patch(changes, {})
result["value"]["items"].append(2)
assert patch(changes, {}) == {"value": {"items": [1]}}
The assertion fails on current master because the second result contains [1, 2]. The diff should remain reusable independently of the objects produced by applying it. Regression tests reproduce this for add/change and both values of in_place.
patch()inserts mutable values from a diff directly into the destination. Mutating the patched result then changes the diff and affects subsequent applications, even with the defaultin_place=False. This occurs for both added and replaced values.The assertion fails on current master because the second result contains
[1, 2]. The diff should remain reusable independently of the objects produced by applying it. Regression tests reproduce this for add/change and both values ofin_place.