Enforce a sort order when collecting prefetched files for a diff.

Review Request #11736 — Created July 21, 2021 and submitted — Latest diff uploaded

Information

Review Board
release-4.0.x

Reviewers

When collecting FileDiffs in DiffSet.per_commit_files() and
DiffSet.cumulative_files(), it was possible to get files that weren't
in an expected order. These could come from the database in index order
and not insertion order. While this generally wouldn't be a huge
problem for general lookups of files (and wasn't a problem for all
database setups), it could lead to out-of-order raw diffs, which could
easily break anything trying to access them.

This is an edge case for sure, and one where we don't have a good
reproduction case. It seems to be dependent on the database.

We now explicitly force an order based on the primary key. Currently,
we're only enforcing them in these properties, and not as the default
sort order for the model, in order to avoid any unintentional side
effects.

Unit tests pass.

Tested in production with a customer who encountered this problem. We
verified the fix.

Commits

Files

    Loading...