Fix more caching issues in WebAPIResource with etag generation.

Review Request #7027 — Created March 9, 2015 and submitted — Latest diff uploaded

Information

Djblets
release-0.8.x
5145720...

Reviewers

WebAPIResource's newer etag generation code was incomplete. It assumed
it could safely serialize any value looked up from the field. However,
this failed to handle QuerySets, Managers, ForeignKeys, links, etc.

We now call serialize_object and use this for the pre-encoded ETag
value. To ensure we don't hit the database more than we need to, we now
keep a cached copy of the results of serialize_object (using deepcopy,
in order to prevent the cached copy from changing if the caller modifies
the result). This ensures that the ETag is built from the payload that
will be sent to the user (minus the aforementioned modifications, which
are up to the caller to deal with as needed).

All unit tests pass on Djblets and RB.

ETags are no longer changing on subsequent requests.