Repository navigation
[18.0][FIX] fs_attachment: don't crash on fs streams without mimetype - #685
Conversation
|
Hi @lmignon, |
aa3aa94 to
a3453e7
Compare
|
Thanks for the review @lmignon! I've addressed your comments:
I amended the existing commit to keep a single commit. Could you take another look? |
lmignon
left a comment
There was a problem hiding this comment.
@jowyto " Co-Authored-By: Claude is not allowed. " You must retain full responsibility and ownership of any code you contribute to OCA, as stated in the OCA AI policy.
| mimetype instead of crashing. | ||
| """ | ||
| attachment = self._create_attachment_without_extension() | ||
| self.env.cr.execute( |
There was a problem hiding this comment.
nit: flush the record before writing the column with raw SQL. If a later change to ir.attachment leaves mimetype dirty in the cache after create, the next flush would write it back over the NULL and the test would pass without exercising the empty-mimetype path.
| self.env.cr.execute( | |
| attachment.flush_recordset() | |
| self.env.cr.execute( |
For "fs" streams, the mimetype is taken as is from the attachment and may be empty for attachments written outside the ORM. Since OCA#584, ir.binary._get_stream_from then called guess_extension(False), and FsStream.get_response passed mimetype=False to werkzeug: both raised an AttributeError and the download returned a 500. Fall back to default_mimetype for fs streams with no mimetype, as core does for "data" and "path" streams, and only run the extension guess for fs streams, since core already does it for the other stream types. Fixes OCA#684
a3453e7 to
3f25132
Compare
|
/ocabot merge patch |
|
This PR looks fantastic, let's merge it! |
|
This PR has the |
|
Congratulations, your PR was merged at 8e8301f. Thanks a lot for contributing to OCA. ❤️ |
Fixes #684
For
fsstreams, the mimetype is taken as is from the attachment (FsStream.from_fs_attachment) and may be empty for attachments written outside the ORM (imports, migrations). Two things then return a 500 on/web/content/<id>:ir.binary._get_stream_fromcallsguess_extension(stream.mimetype)for every stream type, andguess_extension(False)raisesAttributeError;FsStream.get_responsepassesmimetype=Falseto werkzeug'ssend_file, which also raisesAttributeError.Core avoids this for
data/pathstreams by filling an empty mimetype withguess_mimetype(head, default=default_mimetype)before adding the extension.This PR:
default_mimetypeforfsstreams with no mimetype, without reading the file from the storage to sniff it;fsstreams, since core already does it fordata/pathand leavesurlstreams alone.Tests in
test_stream.py:test_content_url_without_mimetype: fails before the fix and passes after;test_content_url_name_without_extension: covers the [18.0][IMP] fs_attachment: enhance stream download name handling based on mimetype #584 behaviour, which had no test.fs_attachmenttests: 40 passed with the fix; without it,test_content_url_without_mimetypeerrors.This is part of the work at Capitalizarme, where we run fs_attachment / fs_attachment_s3 on Odoo 18.0 Enterprise (odoo.sh). The same code is in 19.0 and 20.0; happy to forward-port once this is reviewed.
🤖 Generated with Claude Code