Skip to content

Incorrect patch produced #55

Description

@trvrm
src =  [{'a': 1},{'b': 2}]
dst =  [{'a': 1,'b': 2}]

patch = jsonpatch.make_patch(src,dst)
print(patch.patch)
print(patch.apply(src))
assert patch.apply(src)==dst

produces the following patch

[
    {'op': 'remove', 'path': '/1'}, 
    {'op': 'replace', 'value': 1, 'path': '/0/a'}
]

Which when applied to src produces

[{'a': 1}]

which is obviously incorrect, and fails the assertion.

Activity

  1. mrhadenough commented on Mar 7, 2017

    @mrhadenough
    Contributor

    The problem comes from the optimization function https://github.com/stefankoegl/python-json-patch/blob/master/jsonpatch.py#L772
    It should not make a patch of the operations "remove" and "add" cause it's not the source and destination objects, so need to treat differently.

  2. stefankoegl commented on Mar 7, 2017

    @stefankoegl
    Owner

    @mrhadenought thanks for your comment. As you can probably see, I didn't have enough time to devote to the development of jsonpatch recently. If you could write up a pull request, I'd make sure to verify it and release a new version promptly.

  3. stefankoegl commented on Jun 15, 2017

    @stefankoegl
    Owner

    This should have been resolved by #59. I will release a new version soon.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions