inveniosoftware / inveniosoftware/dictdiffer

Patching shares mutable values with the input diff

Open Beginner friendly
#205 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
849
Forks
99
PR merge metrics
No merged PRs in 30d

Description

`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.

```python
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`.

Contributor guide

Open the contributing guide

Research direction

Start at the patch() implementation and trace how added and replaced values from the diff are inserted into the destination. Add regression tests for add and change cases with both in_place values, verifying that mutating one patched result does not alter the reusable diff or later results.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.