Describe the issue
When migrating Document Attachment records to external storage, multiple Document Attachment records can reference the same Tenant Media record. If the migration deletes the Tenant Media record immediately after processing the first attachment, subsequent attachments referencing the same media fail because the underlying media no longer exists.
The migration processes Document Attachment records individually.
For each attachment it:
- Reads the file from Document Reference ID.
- Uploads the file to Azure Blob Storage.
- Marks the attachment as stored externally.
- Deletes the associated Tenant Media record.
The problem is that Document Reference ID is a Media field, and multiple Document Attachment records may reference the same Tenant Media record.
A common example is when a document is posted. The attachment on the posted document frequently references the same Tenant Media record as the original document rather than creating a duplicate media record.
As a result:
- Attachment A is migrated successfully.
- The shared Tenant Media record is deleted.
- Attachment B, which references the same media, can no longer retrieve the file.
- The migration fails for Attachment B.
Expected behavior
The migration should recognise that multiple Document Attachment records can reference the same Tenant Media record.
A Tenant Media record should only be deleted after every referencing Document Attachment has been successfully migrated.
Steps to reproduce
- Create a Purchase Invoice.
- Add a document attachment.
- Post the document.
- Verify that both the original and posted Document Attachment records reference the same Tenant Media record (Document Reference ID.Id).
- Run the external storage migration.
- Observe that the first attachment is migrated successfully.
- Observe that subsequent attachments referencing the same Tenant Media record fail because the media has already been deleted.
Additional context
No response
I will provide a fix for a bug
Describe the issue
When migrating Document Attachment records to external storage, multiple Document Attachment records can reference the same Tenant Media record. If the migration deletes the Tenant Media record immediately after processing the first attachment, subsequent attachments referencing the same media fail because the underlying media no longer exists.
The migration processes Document Attachment records individually.
For each attachment it:
The problem is that Document Reference ID is a Media field, and multiple Document Attachment records may reference the same Tenant Media record.
A common example is when a document is posted. The attachment on the posted document frequently references the same Tenant Media record as the original document rather than creating a duplicate media record.
As a result:
Expected behavior
The migration should recognise that multiple Document Attachment records can reference the same Tenant Media record.
A Tenant Media record should only be deleted after every referencing Document Attachment has been successfully migrated.
Steps to reproduce
Additional context
No response
I will provide a fix for a bug