Module
fs_attachment
Branches affected: verified on 19.0 (19.0.1.1.1). but same code since 16.0
Describe the bug
When an ir.attachment is stored on an external filesystem storage, its thumbnail field is not correctly served.
The issue is caused by _get_fs_attachment_for_field() returning the parent attachment as soon as record.fs_filename is set, without taking field_name into account:
if record._name == "ir.attachment" and record.fs_filename:
return record
For a request such as:
/web/image/ir.attachment/<id>/thumbnail
Odoo calls _record_to_stream(record, "thumbnail").
If the parent attachment is externalized, fs_attachment returns the parent attachment itself and streams the original file instead of letting Odoo resolve the dedicated attachment storing the thumbnail field.
This results, for example, in the original PDF being served instead of its generated JPEG thumbnail.
A simple fix could be:
if (
record._name == "ir.attachment"
and field_name != "thumbnail"
and record.fs_filename
):
return record
or to avoid futur cases:
def _get_fs_attachment_for_field(self, record, field_name):
field_def = record._fields.get(field_name)
if (record._name == "ir.attachment" and record.fs_filename
and not (
field_def
and field_def.attachment
)
):
return record
if field_def:
record._check_field_access(field_def, "read")
...
To Reproduce
Affected versions:
- Odoo 19.0
- OCA
storage 19.0
fs_attachment
Steps to reproduce the behavior:
- Configure
fs_attachment with an external storage such as S3.
- Upload a PDF attachment, for example in the chatter of a res.partner, so that the original file is stored externally.
- Let Odoo generate its thumbnail.
- The attachment remains available and can be downloaded correctly, but its thumbnail is not displayed in the chatter.
- Open:
/web/image/ir.attachment/<attachment_id>/thumbnail
The original externally stored PDF is served instead of the thumbnail.
As a control test, the same URL works correctly when the attachment is stored using the standard Odoo filestore.
In this case, the thumbnail is displayed correctly.
Expected behavior
When field_name == "thumbnail", fs_attachment should not immediately return the parent attachment just because it has an fs_filename.
Odoo should be allowed to resolve the thumbnail field to its dedicated attachment and stream that image.
A minimal fix would be:
if (
record._name == "ir.attachment"
and field_name != "thumbnail"
and record.fs_filename
):
return record
Additional context
The thumbnail itself is correctly generated and valid.
Direct access to the thumbnail attachment works:
/web/image/<thumbnail_attachment_id>
The issue only occurs when accessing the thumbnail through the parent attachment field:
/web/image/ir.attachment/<parent_attachment_id>/thumbnail
Environment used for reproduction:
- Odoo 19.0
- OCA
storage 19.0
fs_storage
fs_attachment
- S3-compatible Scaleway Object Storage
Module
fs_attachmentBranches affected: verified on 19.0 (19.0.1.1.1). but same code since 16.0
Describe the bug
When an
ir.attachmentis stored on an external filesystem storage, itsthumbnailfield is not correctly served.The issue is caused by
_get_fs_attachment_for_field()returning the parent attachment as soon asrecord.fs_filenameis set, without takingfield_nameinto account:For a request such as:
Odoo calls
_record_to_stream(record, "thumbnail").If the parent attachment is externalized,
fs_attachmentreturns the parent attachment itself and streams the original file instead of letting Odoo resolve the dedicated attachment storing thethumbnailfield.This results, for example, in the original PDF being served instead of its generated JPEG thumbnail.
A simple fix could be:
or to avoid futur cases:
To Reproduce
Affected versions:
storage19.0fs_attachmentSteps to reproduce the behavior:
fs_attachmentwith an external storage such as S3.The original externally stored PDF is served instead of the thumbnail.
As a control test, the same URL works correctly when the attachment is stored using the standard Odoo filestore.
In this case, the thumbnail is displayed correctly.
Expected behavior
When
field_name == "thumbnail",fs_attachmentshould not immediately return the parent attachment just because it has anfs_filename.Odoo should be allowed to resolve the
thumbnailfield to its dedicated attachment and stream that image.A minimal fix would be:
Additional context
The thumbnail itself is correctly generated and valid.
Direct access to the thumbnail attachment works:
The issue only occurs when accessing the thumbnail through the parent attachment field:
Environment used for reproduction:
storage19.0fs_storagefs_attachment