Commit Graph
1 Commits
Author SHA1 Message Date
Alex KandGitHub ce47cda948 Read report/label templates in binary mode (#12432)
* Read report/label templates in binary mode

file_from_template read the template in text mode and wrapped the string
in a ContentFile. The ContentFile size then reflected the character count,
which differs from the UTF-8 byte length for any template that contains
multi-byte characters. Strict S3 implementations such as Backblaze B2
validate the Content-Length header and reject the upload with an
IncompleteBody error. AWS S3 tolerates the mismatch, so the problem is
not visible there.

inventree_transfer_order_report.html is 1458 characters but 1460 bytes.
Its upload fails during create_default_reports, the transaction rolls
back, and the default template is recreated and fails again on every
startup.

Use Path.read_bytes() so the ContentFile size matches the uploaded bytes
and the file handle is closed. Add a regression test asserting the size
equals the file's byte length.

* Test file_from_template across text encodings
2026-07-21 20:17:17 +10:00