[Bug]: External File Attachment - Migrating files fails for Tenant Media referenced more than once.
Nobody has claimed this yet.
- Dominant language
- AL
- Stars
- 683
- Forks
- 459
- Avg merge
- 3d 26m
- Merged PRs (30d)
- 633
Description
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
- I will provide a fix for a bug
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the external storage migration that processes Document Attachment records, reads Document Reference ID, uploads to Azure Blob Storage, and deletes Tenant Media. Trace how shared media references are handled and add or run coverage for attachments sharing one Tenant Media record. Done means every referencing attachment migrates successfully before the shared media is deleted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100