Skip to content

Incorrect patch produced #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
trvrm opened this issue Aug 26, 2016 · 3 comments
Closed

Incorrect patch produced #55

trvrm opened this issue Aug 26, 2016 · 3 comments

Comments

@trvrm
Copy link

trvrm commented Aug 26, 2016

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.

@mrhadenough
Copy link
Contributor

mrhadenough commented Mar 7, 2017

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.

@stefankoegl
Copy link
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.

mrhadenough added a commit to mrhadenough/python-json-patch that referenced this issue Mar 8, 2017
mrhadenough added a commit to mrhadenough/python-json-patch that referenced this issue Mar 8, 2017
mrhadenough added a commit to mrhadenough/python-json-patch that referenced this issue Mar 8, 2017
@stefankoegl
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants