stefankoegl / python-json-patch

Applying JSON Patches in Python
https://python-json-patch.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
440 stars 96 forks source link

better exception when a 'path' points to a non existing location #89

Closed guillp closed 6 years ago

guillp commented 6 years ago

Please consider the following test case:

from jsonpatch import JsonPatch
obj = {'attribute': 'value'}
patch = JsonPatch([{'op': 'add', 'path': '/attribute/4', 'value': 'foo'}])
patch.apply(obj)

This raises a TypeError: invalid document type <class 'str'>. With the proposed pull request, it returns a JsonPatchConflict: unable to fully resolve json pointer /attribute/4, part 4

stefankoegl commented 6 years ago

Looks good, thanks :)