Skip to content

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

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
jowyto:18.0-fix-fs_attachment-stream-no-mimetype
Dec 4, 2026
Merged

OCA-git-bot merged 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/models/ir_binary.py Resolved
Comment thread fs_attachment/models/ir_binary.py Resolved
@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

@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.

@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.

@CRogos CRogos 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.

LGTM, beside findings of @lmignon

Minor finding by AI on the test below.

mimetype instead of crashing.
"""
attachment = self._create_attachment_without_extension()
self.env.cr.execute(

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.

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.

Suggested change
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
@jowyto
jowyto force-pushed the 18.0-fix-fs_attachment-stream-no-mimetype branch from a3453e7 to 3f25132 Compare December 3, 2026 19:28
@lmignon

lmignon commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

/ocabot merge patch

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 18.0-ocabot-merge-pr-685-by-lmignon-bump-patch, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 8e8301f. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants