Skip to content

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

Description

@dorianwoolger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApprovedThe issue is approvedIntegrationGitHub request for Integration area

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions