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

PATCH request should be atomic #20

Open
risseraka opened this issue Feb 1, 2015 · 1 comment
Open

PATCH request should be atomic #20

risseraka opened this issue Feb 1, 2015 · 1 comment

Comments

@risseraka
Copy link
Contributor

Per HTTP PATCH spec

 Note that the HTTP PATCH method is atomic, as per [RFC5789].
   Therefore, the following patch would result in no changes being made
   to the document at all (because the "test" operation results in an
   error):

   [
     { "op": "replace", "path": "/a/b/c", "value": 42 },
     { "op": "test", "path": "/a/b/c", "value": "C" }
   ]

Ref: http://tools.ietf.org/html/rfc6902#section-5

In other words, none of a patch's operations should be applied if any one of them fails.

> var obj = {};
undefined

> jsonpatch.apply(obj, [
  {op: 'add', path: '/foo', value: 'bar'}, 
  {op: 'remove', path: '/baz'}
]);
PatchConflictError: Value at baz does not exist // OK

> obj
{ foo: 'bar' }  // NOT OK

jsonpatch.apply should perhaps test every operations before applying them.

What do you think?

@bruth
Copy link
Owner

bruth commented Feb 2, 2015

You are free to make a copy of the object prior to applying the set of operations. The README disclaims this: Note: at this time, all operations are applied in-place.

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