Skip to content

[16.0-19.0][BUG] fs_attachment serves parent attachment instead of thumbnail for externally stored files #664

Description

@Lionel-cl

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:

  1. Configure fs_attachment with an external storage such as S3.
  2. Upload a PDF attachment, for example in the chatter of a res.partner, so that the original file is stored externally.
  3. Let Odoo generate its thumbnail.
  4. The attachment remains available and can be downloaded correctly, but its thumbnail is not displayed in the chatter.
  5. 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

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