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:
- Set an
fs.storage (e.g. s3) with use_as_default_for_attachments.
- Upload a PDF in the Documents app (big enough to be offloaded).
- 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.
Module
fs_attachment
Describe the bug
With an
fs.storageset asuse_as_default_for_attachments, opening anoffloaded 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 relatedfield (
related="attachment_id.raw")._get_fs_attachment_for_field()(
fs_attachment/models/ir_binary.py) ignores related fields(
field_def.storeis False), so streaming falls back to the baseimplementation, which builds a local filestore path from the
fs_code://...store_fname: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:
fs.storage(e.g. s3) withuse_as_default_for_attachments.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
documentsmodule overridesir.binary._record_to_stream(documents/models/ir_binary.py) and returns
Stream.from_attachment(record.attachment_id)directly, WITHOUT callingsuper() — 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_attachmentanddocuments(so it comes first in the MRO):_record_to_stream: if the record is adocuments.documentwhose
attachment_idlives on an FS storage, returnFsStream.from_fs_attachment(attachment); otherwise call super();_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.