Add enhanced support for extra_data and JSON patching.

Review Request #12251 — Created April 22, 2022 and submitted — Latest diff uploaded

Information

RBTools
release-3.x

Reviewers

This brings some long-needed support for working with modern
extra_data functionality in Review Board.

Attempting to modify an extra_data dictionary now raises an exception.
This is part of the work done to make dictionary fields immutable, since
RBTools doesn't have a concept of simply saving a resource back to the
server (update() calls are required instead). The immutable error
provides handy instructions for setting new extra_data content.

The big change here, though, is the support for extra_data patching.
This was doable before through something like:

resource.update(**{'extra_data:json': json.dumps({...})})

That obviously was not ideal. Now, callers can simply set the
extra_data_json field to a native dictionary to do a JSON Merge Patch
or set extra_data_json_patch to a list of dictionaries to do a JSON
Patch. RBTools will properly serialize the results to JSON, setting the
correct key in the payload.

A .copy() method also exists to return a copy of the original field
data, without any wrapping. This works for any dictionary level of
extra_data, allowing consumers to create a copy, manipulate it, and
set it as a new full dictionary in a patch request.

Between new patching options, a more standard dictionary interface, the
ability to copy the payload, and useful immutable error handling, it
should now be a lot easier to work with extra_data fields.

Unit tests pass on all supported versions of Python.

Commits

Files