Defect #33769

When creating more than two identical attachments in a single db transaction, the first one always ends up unreadable

Added by Jens Krämer 4 months ago. Updated 2 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Go MAEDA% Done:

0%

Category:Attachments
Target version:4.0.8
Resolution:Fixed Affected version:

Description

Due to the file re-using code running in an after_commit hook, the hooks of any attachments that are created in a common db transaction will be deferred and run one after another after the outer transaction was committed. The existing implementation does not take that into account and as a consequence, when creating more than two identical attachments in a single transaction, the first attachment will end up with a non-existing diskfile.

The attached patch includes a test reproducing the issue and a fix, which consists of using last instead of first when finding an existing attachment to re-use. This way, the selected attachment is consistent across all runs of the hook even if multiple candidates exist. I also added an explicit order call for good measure.

This is a corner case that should never occur in normal Redmine usage - but may occur in 3rd party code that's creating many attachments wrapped in a transaction.

0001-fix-creation-of-multiple-identical-attachments-in-ou.patch Magnifier (1.96 KB) Jens Krämer, 2020-07-26 10:19


Related issues

Duplicated by Redmine - Defect #28440: After commit missing file Closed

Associated revisions

Revision 20094
Added by Go MAEDA 2 months ago

When creating more than two identical attachments in a single transaction, the first one always ends up unreadable (#33769).

Patch by Jens Krämer.

Revision 20095
Added by Go MAEDA 2 months ago

Merged r20094 from trunk to 4.1-stable (#33769).

Revision 20096
Added by Go MAEDA 2 months ago

Merged r20094 from trunk to 4.0-stable (#33769).

History

#1 Updated by Go MAEDA 2 months ago

  • Target version set to 4.0.8

Setting the target version to 4.0.8.

#2 Updated by Go MAEDA 2 months ago

#3 Updated by Go MAEDA 2 months ago

  • Tracker changed from Patch to Defect
  • Status changed from New to Resolved
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix. Thank you for your contribution.

#4 Updated by Go MAEDA 2 months ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF