Repository navigation
Conversation
An attachment stored in an `fs.storage` whose `mimetype` is empty is served as `False`, and two places crash on it: `guess_extension()` in `_get_stream_from` and werkzeug's `send_file` in `FsStream.get_response`, both with `AttributeError: 'bool' object has no attribute ...`. Core fills the empty mimetype for `data`/`path` streams with `default_mimetype`; do the same for `fs` streams. The extension guess moves inside the `fs` branch, since it only applies to those streams. The mimetype can be empty for attachments written outside the ORM: imports, migrations, or code writing the column directly. Forward-port of OCA#685 to 19.0.
|
Hi @lmignon, |
polcerverapyming
left a comment
There was a problem hiding this comment.
Tested on Odoo 19.0. An fs attachment with an empty mimetype no longer crashes: _get_stream_from falls back to the default mimetype and /web/content/ returns 200 instead of 500, while extension guessing for fs streams still works. Works as expected. LGTM
@polcerverapyming It can't be merged since the authorship is not preserved into the forward port process of the original PR... |
An attachment stored in an
fs.storagewhosemimetypeis empty is served asFalse, and two places crash on it:IrBinary._get_stream_fromcallsguess_extension(stream.mimetype)for everystream type (since [18.0][IMP] fs_attachment: enhance stream download name handling based on mimetype #584), so
FalseraisesAttributeError: 'bool' object has no attribute 'lower';FsStream.get_responsepassesmimetype=Falseto werkzeug'ssend_file,which raises
AttributeError: 'bool' object has no attribute 'startswith'.Core fills the empty mimetype for
data/pathstreams withdefault_mimetype(
guess_mimetype(head, default=default_mimetype)); this does the same forfsstreams. The extension guess moves inside the
fsbranch, since it onlyapplies to those streams.
The mimetype can be empty for attachments written outside the ORM: imports,
migrations, or code writing the column directly.
GET /web/content/<id>onsuch an attachment returned a 500.
Verification on 19.0:
TestStream—0 failed, 0 error(s) of 9 tests;test_content_url_without_mimetypeerrors with
AttributeError: 'bool' object has no attribute 'lower', so theregression test does catch it.
Forward-port of #685 to 19.0 — same change, same tests, plus the newsfragment.
Fixes #684