stefankoegl/python-json-patch — pull request #22 by umago (2014-01-22 17:10:08+00:00)
Title: Catch KeyError when accessing the sub-doc items

In [12]: doc = {'param1': 1, 'param2': {'oi' :'ola'}}
In [13]: patch = [{'op': 'remove', 'path': '/invalid'}]
In [14]: jsonpatch.apply_patch(doc, jsonpatch.JsonPatch(patch))
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in ()
----> 1 jsonpatch.apply_patch(doc, jsonpatch.JsonPatch(patch))

/usr/lib/python2.7/site-packages/jsonpatch.pyc in apply_patch(doc, patch, in_place)
139 else:
140 patch = JsonPatch(patch)
--> 141 return patch.apply(doc, in_place)
142
143 def make_patch(src, dst):

/usr/lib/python2.7/site-packages/jsonpatch.pyc in apply(self, obj, in_place)
342
343 for operation in self._ops:
--> 344 obj = operation.apply(obj)
345
346 return obj

/usr/lib/python2.7/site-packages/jsonpatch.pyc in apply(self, obj)
393 subobj, part = self.pointer.to_last(obj)
394 try:
--> 395 del subobj[part]
396 except IndexError as ex:
397 raise JsonPatchConflict(str(ex))