Fix stale query caches when publishing review request drafts via the API.

Review Request #8422 — Created Sept. 20, 2016 and submitted

Information

Review Board
release-2.5.x
bf2cbf6...

Reviewers

We recently hit an issue where Review Bot was unable to find any diffs
on newly-created review requests. This ended up being due to stale query
caches caused by select_related() and prefetch_related() queries from
ReviewRequestResource.get_queryset(), which would get called by
ReviewRequestDraftResource.update() prior to publishing.

Those caches were intended to reduce queries when requesting a list of
resources, but interfered with operations when working with single
items. In this case, it resulted in any signal handlers for the
published signals being unable to query for change descriptions or
diffsets using relations from the review request, returning only stale
results. While the diffset bug is relatively new, the change
descriptions bug has been around a long while, and simply hasn't been
hit in production yet.

This change updates the queryset calculation to only select/prefetch
related objects when returning a list of items.

A unit test was added that reliably reproduces our Review Bot failure
case (along with a failure involving change description query caches).

Unit tests failed before the fix with the same failure case experienced
with Review Bot. After the fix, unit tests pass.

david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.5.x (6f4b45f)
Loading...