Skip to content

Patching shares mutable values with the input diff #205

Description

@vitalivo

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions