Skip to content

[17.0] fs_attachment: 500 when previewing files in the Documents app #642

Description

@TepavaDT

Module

fs_attachment

Describe the bug

With an fs.storage set as use_as_default_for_attachments, opening an
offloaded file in the Enterprise Documents app returns HTTP 500. Chatter
attachments and direct /web/content/<attachment_id> URLs work fine.

Cause: the Documents app streams documents.document.raw, a related
field (related="attachment_id.raw"). _get_fs_attachment_for_field()
(fs_attachment/models/ir_binary.py) ignores related fields
(field_def.store is False), so streaming falls back to the base
implementation, which builds a local filestore path from the
fs_code://... store_fname:

FileNotFoundError: '/home/odoo/data/filestore/<db>/fs_code:/<filename>'

Same problem as #313 (16.0), closed as stale without a fix.

To Reproduce

Affected versions: 17.0 (fs_attachment 17.0.1.6.2), likely 16.0+ (#313)

Steps to reproduce the behavior:

  1. Set an fs.storage (e.g. s3) with use_as_default_for_attachments.
  2. Upload a PDF in the Documents app (big enough to be offloaded).
  3. Open its preview in Documents → 500.

Expected behavior
The file is streamed from the FS storage, like chatter attachments are.

Additional context
The related field is only part of the problem for the Documents app: the
Enterprise documents module overrides ir.binary._record_to_stream
(documents/models/ir_binary.py) and returns
Stream.from_attachment(record.attachment_id) directly, WITHOUT calling
super() — so fs_attachment is never given a chance to serve the file, and
the base Stream builds a local filestore path from the fs_code://...
store_fname.

Fix that works for us — a small bridge module depending on both
fs_attachment and documents (so it comes first in the MRO):

  • override _record_to_stream: if the record is a documents.document
    whose attachment_id lives on an FS storage, return
    FsStream.from_fs_attachment(attachment); otherwise call super();
  • additionally, resolve related binary field chains in
    _get_fs_attachment_for_field() for the generic (non-Documents) case.

Since the Enterprise override cannot be patched by OCA, an optional glue
module in OCA/storage (auto_install on fs_attachment + documents) might be
the right shape.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions