Skip to content

[19.0][FIX] fs_attachment: don't upload files forced to DB - #674

Closed
HviorForgeFlow wants to merge 1 commit into
OCA:19.0from
ForgeFlow:19.0-fix-fs_attachment-forced_db_upload
Closed

HviorForgeFlow wants to merge 1 commit into
OCA:19.0from
ForgeFlow:19.0-fix-fs_attachment-forced_db_upload

Conversation

@HviorForgeFlow

Copy link
Copy Markdown
Member

Since Odoo 19, ir.attachment create() and _set_attachment_data() write the file after _get_datas_related_values() for every attachment when the storage is not 'db', including the ones fs_attachment forces to the database through force_db_for_default_attachment_rules. The file is then uploaded to the storage for nothing: it is referenced by no attachment and only removed later by the fs.file.gc, and the write fails when the storage is unreachable, so an attachment meant to be kept in the database cannot be written while the storage is down (e.g. menu icons during a module update).

Skip the write in _file_write when the content was forced to the database in the current transaction and no attachment references the file. Contents shared with an attachment kept in the storage, and the files written by AttachmentFileLikeAdapter, are still written.

Regression tests included: no file written on create/write, create succeeds with the storage unreachable, and shared contents are still written in both orders.

Assisted-by: Claude Opus 5.5

Since Odoo 19, ir.attachment create() and _set_attachment_data() write
the file after _get_datas_related_values() for every attachment when
the storage is not 'db', including the ones fs_attachment forces to
the database through force_db_for_default_attachment_rules. The file
is then uploaded to the storage for nothing: it is referenced by no
attachment and only removed later by the fs.file.gc, and the write
fails when the storage is unreachable, so an attachment meant to be
kept in the database cannot be written while the storage is down.

Skip the write in _file_write when the content was forced to the
database in the current transaction and no attachment references the
file. Contents shared with an attachment kept in the storage, and the
files written by AttachmentFileLikeAdapter, are still written.

Assisted-by: Claude Opus 5.5
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

Comment on lines +387 to +397
if checksum not in self.env.cr.cache.get(
"fs_attachment_forced_to_db_checksums", ()
):
return False
store_fname = f"{location}://{self._get_fs_path(location, bin_data)}"
self.flush_model(["store_fname"])
self.env.cr.execute(
"SELECT 1 FROM ir_attachment WHERE store_fname = %s LIMIT 1",
(store_fname,),
)
return not self.env.cr.fetchone()

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.

For sure this code is written by Claude and is a 🤮 hack...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants