Fix lost FileDiffs when using condensediffs on Postgres.
Review Request #8161 — Created May 13, 2016 and submitted — Latest diff uploaded
The condensediffs management command was trying to determine whether a more efficient update can be performed for batch-updating FileDiffs when migrating to the new diff storage format. However, the way it was doing this was only compatible with MySQL, resulting in it falling back to the slower method for Postgres. Unfortunately, the slower method also failed to update entries on Postgres, and this would result in FileDiffs retaining their relations to the old objects. Those objects would then be deleted, deleting the FileDiffs as well, which is a pretty serious bug. Somehow, we haven't heard of this in the wild (and it only happens explicitly with condensediffs). This fixes this by both fixing the cause of the failed updates (a bad "__in" that works in SQLite but not Postgres) and by getting rid of the "generic" check for the smarter updating, replacing it with specific code for MySQL and for Postgres. Condensing also now performs sanity-checks when DEBUG is True, to help us catch issues sooner.
Tested on MySQL, Postgres, and SQLite, with large numbers of diffs.
Verified that the diffs had the expected content in the end. The
sanity checks also passed.