Skip to content

Fails to understand new key in an existing object inside a list #16

@mwgamble

Description

@mwgamble

I ran this code:

from patchdiff import diff
old_val = {"conditions": [{"type": "Ready"}]}
new_val = {"conditions": [{"type": "Ready", "message": "test"}]}
diff(old_val, new_val)

And received the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 136, in diff
    return diff_dicts(input, output, ptr)
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 110, in diff_dicts
    key_ops, key_rops = diff(input[key], output[key], ptr.append(key))
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 134, in diff
    return diff_lists(input, output, ptr)
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 88, in diff_lists
    padded_rops, _ = reduce(partial(pad, target=output), solution["rops"], [[], 0])
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 83, in pad
    replace_ops, _ = diff(op["original"], op["value"], replace_ptr)
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 136, in diff
    return diff_dicts(input, output, ptr)
  File ".venv/lib/python3.10/site-packages/patchdiff/diff.py", line 99, in diff_dicts
    rops.insert(0, {"op": "add", "path": ptr.append(key), "value": output[key]})
KeyError: 'message'

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