• 
      

    Define the local site field for file attachments on creation.

    Review Request #15164 — Created July 11, 2026 and updated — Latest diff uploaded

    Information

    Review Board
    release-8.x

    Reviewers

    Local sites for file attachments have a messy history. Currently, the
    local_site foreign key is only present for user file attachments
    (attachments that were uploaded into a comment box or from the user file
    attachments API), and for ones linked to file diffs (although our docs
    erroneously do not mention this). Attachments that are uploaded directly to
    a review request do not have this relation populated. Instead we grab the
    local site from their related review request. We have a get_local_site()
    method, which was originally added to help grab the right local site
    depending on the type of file attachment.

    We recently ran into a problem where we needed to grab a file attachment's
    local site before it has been linked to its review request. But we currently
    have no way of doing so.

    This change improves things by always setting the local_site field on
    file attachment creation. For existing pre-RB8.1 file attachments, calling
    get_local_site() will now set the local_site field for ones that
    don't have it set. We have a _defined_local_site key in the file
    attachment's extra data that lets us know that the local_site field value
    is authoritative. We need that because a local_site=None value is ambiguous
    on its own, it can mean that a file attachment doesn't have a local site, or
    that it's a pre-RB8.1 file attachment where we haven't resolved and set the
    local site from its review request yet.

    Did the following tests on my local RB 8 dev server and my local
    RBCommons dev server:
    - Ran unit tests.
    - Created a review request and uploaded a pdf file to it.
    - Created a user file attachment by dragging an image into a comment.
    - rbt posted a change containing binary files.
    - Viewed existing file attachments.

    Also used in upcoming changes that add local site support to
    document review.

    Commits

    Files