microsoft / microsoft/BCApps

[Bug]: External File Attachment - Migrating files fails for Tenant Media referenced more than once.

Open
#9,144 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Approved Team: Integrations
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:

  1. Reads the file from Document Reference ID.
  2. Uploads the file to Azure Blob Storage.
  3. Marks the attachment as stored externally.
  4. 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
  1. Create a Purchase Invoice.
  2. Add a document attachment.
  3. Post the document.
  4. Verify that both the original and posted Document Attachment records reference the same Tenant Media record (Document Reference ID.Id).
  5. Run the external storage migration.
  6. Observe that the first attachment is migrated successfully.
  7. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.