Skip to content
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

"can't remove non-existent object" exception with duplicate dicts in list #91

Open
symroe opened this issue Jan 23, 2019 · 1 comment
Open

Comments

@symroe
Copy link

symroe commented Jan 23, 2019

Here's a test case that fails in 1.23:

from jsonpatch import JsonPatch                                                                                                                                           
from_v = { 
    "foo": [ 
        {"baz": 2}, 
        {"bar": 1}, 
        {"bar": 1}, 
    ] 
}                                                                                                                                                                 

to_v = { 
    "foo": [ 
        {"baz": 2}, 
    ] 
}                                                                                                                                                                 

x = JsonPatch.from_diff(from_v, to_v)                                                                                                                                         
x.apply(to_v) 

The exception is:

Traceback (most recent call last):
  File "/Users/symroe/.envs/jsonpatch_test/lib/python3.6/site-packages/jsonpatch.py", line 385, in apply
    del subobj[part]
IndexError: list assignment index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "jsonpatch_bug.py", line 18, in <module>
    x.apply(to_v)  
  File "/Users/symroe/.envs/jsonpatch_test/lib/python3.6/site-packages/jsonpatch.py", line 312, in apply
    obj = operation.apply(obj)
  File "/Users/symroe/.envs/jsonpatch_test/lib/python3.6/site-packages/jsonpatch.py", line 388, in apply
    raise JsonPatchConflict(msg)
jsonpatch.JsonPatchConflict: can't remove non-existent object '1'

It looks like having two identical dicts in a list causes this, when both dicts are removed from to_v.

@symroe symroe changed the title :q "can't remove non-existent object" exception with duplicate dicts in list Jan 23, 2019
@rmb938
Copy link

rmb938 commented Feb 3, 2019

I am having a similar issue, using the example in the docs

Python 3.6.6
import jsonpatch
src = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
dst = {'baz': 'qux', 'numbers': [1, 4, 7]}
patch = jsonpatch.make_patch(src, dst)
result = patch.apply(doc)

Traceback (most recent call last):
  File "/home/rbelgrave/.local/share/virtualenvs/test-RQFjY04W/lib/python3.6/site-packages/jsonpatch.py", line 385, in apply
    del subobj[part]
KeyError: 'foo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rbelgrave/.local/share/virtualenvs/test-RQFjY04W/lib/python3.6/site-packages/jsonpatch.py", line 312, in apply
    obj = operation.apply(obj)
  File "/home/rbelgrave/.local/share/virtualenvs/test-RQFjY04W/lib/python3.6/site-packages/jsonpatch.py", line 388, in apply
    raise JsonPatchConflict(msg)
jsonpatch.JsonPatchConflict: can't remove non-existent object 'foo'

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

2 participants