Add a SHA256 hash checksum attribute to file attachments.
Review Request #14788 — Created Jan. 27, 2026 and submitted
This adds
FileAttachment.sha256_checksum, a SHA256 file content hash
of a file. We expose this attribute via the API so that callers can use
it to checksum file attachments. We generate and set this hash in our
upload file form, and in another spot where we create a file attachment for
the original version of binary files in the diff viewer. Even if these
two points don't cover all file attachment creation cases, the hash gets
set on demand whenever thesha256_checksumattribute is accessed.This also adds a utility function for creating SHA256 hashes, and a
type hint toFileDiff.get_repository()that was useful for this work.An upcoming change will point
FileDiff.patched_sha256and
FileDiff.orig_sha256to the corresponding
FileAttachment.sha256_checksumfor binary file diffs.
- Ran unit tests.
- Used in an upcoming RBTools change where I access the
sha256_checksum
attribute via the API.
| Summary | ID |
|---|---|
| ab6513c7bbcf2d1e13372cb766912526f8d7dcd1 |
| Description | From | Last Updated |
|---|---|---|
|
Can we do the File import inside if TYPE_CHECKING? |
|
|
|
The argument name is file_content |
|
|
|
If we wanted to be defensive, we could do elif isinstance(file_content, file) (and ignore my comment about File in TYPE_CHECKING) … |
|
|
|
Just to ensure that this works across various backends, we should probably put this all inside a with file_content: block. |
|
|
|
Mind updating this to mention returning None? |
|
|
|
Missing a trailing comma. |
|
|
|
This can probably be a @cached_property, which would avoid the micromanagement around _sha256_checksum. |
|
|
|
Missing parens around the str | None. |
|
|
|
no newline at end of file Column: 55 Error code: W292 |
|
-
-
-
-
If we wanted to be defensive, we could do
elif isinstance(file_content, file)(and ignore my comment aboutFileinTYPE_CHECKING) and then have anelseclause that usestypelets.runtime.raise_invalid_type -
Just to ensure that this works across various backends, we should probably put this all inside a
with file_content:block. -
-
- Commits:
-
Summary ID 565e3081d48ffc5415436b846bc09959a7f58c02 ad2f5f7033d15444987f7f946585c6192c5bc3c5 - Diff:
-
Revision 2 (+584 -52)
- Commits:
-
Summary ID ad2f5f7033d15444987f7f946585c6192c5bc3c5 ab6513c7bbcf2d1e13372cb766912526f8d7dcd1 - Diff:
-
Revision 3 (+580 -52)