Add two new methods for storing JSON extra_data in the API.
Review Request #9271 — Created Oct. 16, 2017 and submitted
Our
extra_data
support in the API has previously been limited to
storing primitive values (strings, booleans, integers) associated with
top-level keys. It didn't allow for any complex JSON data.This change introduces two new methods for storing and managing more
complex JSON data. Clients can now set theextra_data:json
field in
POST or PUT to a serialized JSON Merge Patch, which is a JSON document
that will be merged into the root ofextra_data
. Keys mapped to
dictionaries in the document will merge the dictionary from the JSON
Merge Patch. Arrays will replace arrays. Any key set toNone
will
remove that key from the dictionary. This is a pretty good,
straight-forward way of working with JSON data.For more advanced usage, clients can set
extra_data:json-patch
to a
JSON Patch document, which is a list of operations to perform on
extra_data
. This allows for setting entire JSON structures on
dictionary keys, at the end of an array, or even at specific array
indices. Operations can remove parts of the JSON document, copy/move
data. They can also sanity-check the presence of existing data, aborting
the entire patch if not present.Both forms of patches prevent replacing the entire root resource itself
(though every key can be specifically deleted), so that clients don't
accidentally remove all state. They also obey any access restrictions
imposed by extensions, preventing reading from private parts of a tree
and writing to private/read-only parts of a tree. Keys with double
underscores (__keyname
) are also still supported, and can occur at any
level of the tree.Documentation on all of this will be added in a future change.
Unit tests pass.
Manually tested that both forms of patching work.
Description | From | Last Updated |
---|---|---|
F821 undefined name 'e' |
reviewbot | |
Seems like we should return an error in the negative case. |
david | |
Docs here look fine but should probably be pushed as a separate commit. |
david | |
Having an empty PUT seems like we're no longer exercising some code that we used to. |
david | |
Having an empty PUT seems like we're no longer exercising some code that we used to. |
david |
- Change Summary:
-
Fixed a Review Bot complaint.
- Commit:
-
8c67ea7893e4c7dbf46756f8c77bbcab7e0ea53f7bb040be5b596e01935c0b8b03e8ec33ec78dc97
- Diff:
-
Revision 2 (+971 -154)
Checks run (2 succeeded)
- Change Summary:
-
- Moved the
BaseReviewResource.update_review()
docs into /r/9304/. - Brought back the default PUT data for some tests and instead had the
extra_data
tests override the data completely. - Added an error message when attempting to overrie the root of
extra_data
usingextra_data:json
.
- Moved the
- Commit:
-
7bb040be5b596e01935c0b8b03e8ec33ec78dc978171038caddec06d849a198e036d0689fcb3aff9
- Diff:
-
Revision 3 (+948 -146)