Merge lp:~leonardr/lazr.restful/representation_cache into lp:lazr.restful
Proposed by
Leonard Richardson
Status: | Merged |
---|---|
Approved by: | Guilherme Salgado |
Approved revision: | 34 |
Merged at revision: | not available |
Proposed branch: | lp:~leonardr/lazr.restful/representation_cache |
Merge into: | lp:lazr.restful |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~leonardr/lazr.restful/representation_cache |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Guilherme Salgado (community) | Approve | ||
Review via email: mp+5870@code.launchpad.net |
To post a comment you must log in.
Test: bin/test /pastebin. canonical. com/16818/
Diff: https:/
This branch fixes a lazr.restful bug that was manifesting in Launchpad
as bug 336866: sending 412 ("Precondition Failed") to people who
messed with bugs.
The problem was that IBug.date_ last_modified was being modified behind
the scened by an event listener. The old value for date_last_modified
wasn't removed from the cache of field representations, and so it got
reused when we sent the representation in response to the PATCH
request. We sent a transitional representation, containing all the changes
the client had made, but with the old value for date_last_modified.
The ETag we calculated for that representation was also modified) , and the
transitional. When the client used it on its next request, the
transitional ETag was compared against the ETag for the fullly new
representation (including the change to date_last_
result was a 412 error.
date_last_modified is changed by an ObjectModifiedEvent listener. The
listeners run synchronously, so by the time control returns to
lazr.restful, the field has been changed. The trick is figuring out
which fields were changed.
This branch fixes the problem by changing the way the cache is
invalidated. Instead of iterating over the changeset, we iterate over
the cache. We have a snapshot of the object before it was changed, and
for each field in the cache, we compare the old object's value for
that field to the new object's value. If they're different, we clear
that value from the cache.
To properly test the branch, I introduced a date_last_ modified- like field
to the sample web service. It's updated behind the scenes every time a
client changes a cookbook.
I had to tweak the tests a little bit because they were constantly sending PATCH requests that didn't change anything and assuming that the old ETags were still valid because nothing changed. Now that revision_number is updated every time you make a PATCH request, you can't reuse ETags.