Skip to content

[18.0][FIX] fs_attachment: don't crash on fs streams without mimetype - #685

Open
jowyto wants to merge 1 commit into
OCA:18.0from
jowyto:18.0-fix-fs_attachment-stream-no-mimetype
Open

jowyto wants to merge 1 commit into
OCA:18.0from
jowyto:18.0-fix-fs_attachment-stream-no-mimetype

Conversation

@jowyto

@jowyto jowyto commented Oct 19, 2026

Copy link
Copy Markdown

Fixes #684

For fs streams, 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>:

Core avoids this for data/path streams by filling an empty mimetype with guess_mimetype(head, default=default_mimetype) before adding the extension.

This PR:

Tests in test_stream.py:

fs_attachment tests: 40 passed with the fix; without it, test_content_url_without_mimetype errors.

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

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

@oca-cla-bot

oca-cla-bot Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@lmignon lmignon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix @jowyto A little comment otherwise it looks good to me.

Comment thread fs_attachment/readme/newsfragments/684.bugfix.rst Outdated
Comment thread fs_attachment/models/ir_binary.py Outdated
Comment thread fs_attachment/models/ir_binary.py Outdated
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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jowyto
jowyto force-pushed the 18.0-fix-fs_attachment-stream-no-mimetype branch from aa3aa94 to a3453e7 Compare October 20, 2026 12:42
@jowyto

jowyto commented Oct 20, 2026

Copy link
Copy Markdown
Author

Thanks for the review @lmignon! I've addressed your comments:

  • the newsfragment is now a plain paragraph;
  • I removed both comments in ir_binary.py.

I amended the existing commit to keep a single commit. Could you take another look?

@jowyto
jowyto requested a review from lmignon October 20, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants