Skip to content

[18.0][IMP] fs_attachment: two attachments with same name and content - #640

Open
CRogos wants to merge 1 commit into
OCA:18.0from
c4a8-odoo:18.0-imp-fs_attachment-duplicate-name
Open

[18.0][IMP] fs_attachment: two attachments with same name and content#640
CRogos wants to merge 1 commit into
OCA:18.0from
c4a8-odoo:18.0-imp-fs_attachment-duplicate-name

Conversation

@CRogos

@CRogos CRogos commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

related to: #639

@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

@lmignon lmignon left a comment

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.

Thank you for pointing out this use case, which I hadn't anticipated.
There are several factors to consider:

  • The same file with the same name can be created in different calls to “create.” (This case is not handled.)
  • We need to ensure that deleting an attachment does not delete the file referenced by other attachments (this should not be the case with the garbage collector mechanism)
  • We need to ensure that if I write directly to the file (my_file.open()), only the attachment I wrote to is modified. (This should be the case)

Comment on lines +445 to +450
self.ir_attachment_model.create(
[
{"name": "test.txt", "raw": b"content"},
{"name": "test.txt", "raw": b"content"},
]
)

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.

Can you check you've 2 attachment records with 2 different files. If I update one file, the other one should not be changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this change OK?

Comment on lines +436 to +441
self.ir_attachment_model.create(
[
{"name": "test2.txt", "raw": b"content"},
{"name": "test.txt", "raw": b"content"},
]
)

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.

OK the command create works but can you check the result. Otherwise your tests is partially useless....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previous result was an exception, but I agree we should so some check.

Comment thread fs_attachment/models/ir_attachment.py
@CRogos
CRogos force-pushed the 18.0-imp-fs_attachment-duplicate-name branch from d58b1d0 to 29894f3 Compare July 15, 2026 11:07

@CRogos CRogos left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@lmignon do you have another solution in mind?

Comment thread fs_attachment/models/ir_attachment.py
Comment on lines +436 to +441
self.ir_attachment_model.create(
[
{"name": "test2.txt", "raw": b"content"},
{"name": "test.txt", "raw": b"content"},
]
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The previous result was an exception, but I agree we should so some check.

Comment on lines +445 to +450
self.ir_attachment_model.create(
[
{"name": "test.txt", "raw": b"content"},
{"name": "test.txt", "raw": b"content"},
]
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this change OK?

@CRogos CRogos changed the title [IMP] fs_attachment: two attachments with same name and content [18.0][IMP] fs_attachment: two attachments with same name and content Jul 16, 2026

@lmignon lmignon left a comment

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.

Thank you for the fix, @CRogos. After digging into the code, I fully understood the issue, and your fix is indeed the right one.

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