Fix various issues in FileAttachment.objects.get_for_filediff.
Review Request #13538 — Created Feb. 12, 2024 and submitted — Latest diff uploaded
The
get_for_filediff
method for getting file attachments attached to
diffs had a few major issues that were preventing it from functioning
correctly.First, it was querying solely based on the repository, file path, and
revision. This meant we could theoretically end up returning
FileAttachment
objects which were attached to a different review
request than the givenFileDiff
. While our database schema
theoretically would allow for a single FileAttachment to be attached to
multiple review requests, in practice everything assumes that it's more
of a foreign key relationship than a many to many relationship.Second, when a review request is created with commit history, there are
actually multiple FileDiffs that all go into a single changed file. At
the very least, we'll have a FileDiff for the commit and a FileDiff for
the cumulative diff.When we're posting changes from RBTools, we attach the FileAttachment to
the FileDiff corresponding to the commit. This meant that even though
the file was uploaded, it wasn't visible in the diff viewer because we'd
usually be looking at the cumulative diff.This change makes it so
FileAttachment.objects.get_for_filediff
will
first try the simple case, and if that isn't found, it will check to see
if the DiffSet is created with commit history. If that's the case, we'll
look for the most recent FileDiff object corresponding to the given file
and use that instead.Finally, we mostly were relying on this function to raise
ObjectDoesNotExist
, but we also had a case where it could return
None
. I've changed it to always returnNone
when there are no
matching file attachments.
- Made some queries to filediff API resources and saw that the serialized
attachment fields no longer contained links to file attachments
connected to other review requests. - Posted a change with RBTools that included binary files. Saw that I
could now see those files in the diff viewer. - Ran unit tests.