Skip to content

Fix _compare_lists treating 1 and True as equal in JSON diff#181

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/bugfix-jsondiff-list-equality
Draft

Fix _compare_lists treating 1 and True as equal in JSON diff#181
Copilot wants to merge 2 commits into
masterfrom
copilot/bugfix-jsondiff-list-equality

Conversation

Copilot AI commented Jun 18, 2026

Copy link
Copy Markdown

DiffBuilder._compare_lists used Python's == to skip unchanged list items, but 1 == True in Python causes the diff to miss type changes that are meaningful in JSON.

Changes

  • jsonpatch.py: Replace if old == new: continue with elif self.dumps(old) == self.dumps(new): continue, placed after the isinstance checks for MutableMapping/MutableSequence. This mirrors the existing logic in _compare_values, which already had a comment explaining why dumps-based comparison is necessary.
  • tests.py: Add test_issue180 covering the case where a list contains 1 vs True items.

Example

src = {'aaa': [1, 1, 1]}
dst = {'aaa': [1, True, True]}

patch = jsonpatch.make_patch(src, dst)
res = jsonpatch.apply_patch(src, patch)

# Before fix: patch was empty, res['aaa'] remained [1, 1, 1]
# After fix: patch correctly replaces indices 1 and 2
assert isinstance(res['aaa'][1], bool)  # True
assert isinstance(res['aaa'][2], bool)  # True

Copilot AI changed the title [WIP] Fix jsondiff to correctly handle list item equality comparison Fix _compare_lists treating 1 and True as equal in JSON diff Jun 18, 2026
Copilot AI requested a review from stefankoegl June 18, 2026 06:43
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.

2 participants