diff options
author | Lucas Alvares Gomes <lucasagomes@gmail.com> | 2014-01-22 17:02:42 +0000 |
---|---|---|
committer | Lucas Alvares Gomes <lucasagomes@gmail.com> | 2014-02-03 17:21:05 +0000 |
commit | ad66344ad6ec13403d90a12e959e980a4f1933dd (patch) | |
tree | af2d0e410837980e1f165d304db11cbd817f30f2 /jsonpatch.py | |
parent | d725141a0d5bbd0f9446cc9e3820ccd2ff78cbcd (diff) | |
download | python-json-patch-ad66344ad6ec13403d90a12e959e980a4f1933dd.tar.gz |
Catch KeyError when accessing the sub-doc items
Diffstat (limited to 'jsonpatch.py')
-rw-r--r-- | jsonpatch.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/jsonpatch.py b/jsonpatch.py index a46c9b0..59b3274 100644 --- a/jsonpatch.py +++ b/jsonpatch.py @@ -398,7 +398,7 @@ class RemoveOperation(PatchOperation): subobj, part = self.pointer.to_last(obj) try: del subobj[part] - except IndexError as ex: + except (KeyError, IndexError) as ex: raise JsonPatchConflict(str(ex)) return obj @@ -464,7 +464,10 @@ class MoveOperation(PatchOperation): def apply(self, obj): from_ptr = JsonPointer(self.operation['from']) subobj, part = from_ptr.to_last(obj) - value = subobj[part] + try: + value = subobj[part] + except (KeyError, IndexError) as ex: + raise JsonPatchConflict(str(ex)) if isinstance(subobj, dict) and self.pointer.contains(from_ptr): raise JsonPatchException('Cannot move values into its own children') @@ -512,7 +515,10 @@ class CopyOperation(PatchOperation): def apply(self, obj): from_ptr = JsonPointer(self.operation['from']) subobj, part = from_ptr.to_last(obj) - value = copy.deepcopy(subobj[part]) + try: + value = copy.deepcopy(subobj[part]) + except (KeyError, IndexError) as ex: + raise JsonPatchConflict(str(ex)) obj = AddOperation({ 'op': 'add', |