[RED] Failing tests: migrating a document attachment deletes shared Tenant Media - #10055
Draft
Magnus Hartvig Grønbech (Groenbech96) wants to merge 1 commit into
Draft
[RED] Failing tests: migrating a document attachment deletes shared Tenant Media#10055Magnus Hartvig Grønbech (Groenbech96) wants to merge 1 commit into
Magnus Hartvig Grønbech (Groenbech96) wants to merge 1 commit into
Conversation
Magnus Hartvig Grønbech (Groenbech96)
temporarily deployed
to
triage
August 7, 2026 14:06 — with
GitHub Actions
Inactive
Contributor
|
Could not find a linked ADO work item. Please link one by using the pattern 'AB#' followed by the relevant work item number. You may use the 'Fixes' keyword to automatically resolve the work item when the pull request is merged. E.g. 'Fixes AB#1234' |
…ation Moving a document attachment to external storage deletes its Tenant Media row unconditionally. Tenant Media is shared storage: Document Attachment Mgmt copies attachments onto posted documents with TransferFields, which copies the media reference itself, so several Document Attachment rows can reference a single Tenant Media row. Deleting that row on behalf of one attachment therefore destroys the content of every other attachment copied from it. Those attachments are then skipped silently by UploadToExternalStorage, because Media.HasValue() also verifies that the media exists in the database, so they end up with neither internal content nor an external file. This commit contains tests only. The production code is unchanged, so the failures are attributable to the defect alone. The fix follows in a separate commit. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 45cf5afe-6954-4876-bcec-d2e04bfcb1d8
Magnus Hartvig Grønbech (Groenbech96)
force-pushed
the
copilot/da-shared-tenant-media
branch
from
August 7, 2026 14:12
8a04eec to
96cc1a8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Red run - these tests are expected to FAIL
This commit changes test code only. The production code is untouched, exactly as it is on
main. That is deliberate: the failures are attributable to the defect alone, not to any restructuring of the code under test. The fix follows in a separate commit on this PR.The defect
DA External Storage Impl.DeleteFromInternalStoragedeletes theTenant Mediarow unconditionally after moving an attachment to external storage:Tenant Mediais shared storage.Document Attachment Mgmt.CopyAttachments/CopyAttachmentsForPostedDocscopy attachments onto posted documents withTransferFields+Insert, which copies the media reference rather than the bytes, andDocument Attachment.OnInsertnever re-imports content. So Vendor -> Purchase Header -> Purch. Inv. Header attachments all end up referencing a singleTenant Mediarow.Deleting that row on behalf of one attachment destroys the content of every attachment copied from it. Those attachments are then skipped silently by
UploadToExternalStorage:Media.HasValue()also verifies the media exists in the database, so it returnsfalseand the record is left withStored Externally = false, a blankExternal File Path, and no internal content. Opening it then raisesTenant Media does not exist. ID='{00000000-0000-0000-0000-000000000000}'fromGetAsTempBlob.Note the app already guards the external blob against exactly this hazard -
"Skip Delete On Copy" := ToDocumentAttachment."Stored Externally"protectsDeleteFromExternalStorage. The equivalent protection was never applied to internalTenant Media.Field impact
Observed on a production tenant migrating ~5,200 attachments in one company:
Skips were 0/min while processing Vendor (23), Item (27), Sales Header (36), Purchase Header (38) and Sales Invoice Header (112), then rose to 30-60/min for the entire Purch. Inv. Header (122) block - i.e. the copy targets started failing only once their sources had been migrated.
Tests added
DA Ext. Storage Impl. Tests:DeleteFromInternalKeepsMediaSharedWithCopiedAttachmentTenant Mediasurvives; the copy keeps its contentDeleteFromInternalRemovesMediaWhenNotSharedUploadSucceedsForCopiedAttachmentAfterSourceIsMigratedThe middle test is expected to pass both before and after the fix. It is there to prove the fix does not simply stop reclaiming database space, which is the whole point of the Move operation.
A helper
CreateCopyOfDocumentAttachmentmirrors howDocument Attachment Mgmtcopies attachments, and asserts the shared-media precondition, so the tests cannot pass for the wrong reason if that copy behaviour ever changes.The fix (next commit)
Index-backed by the existing
key(Key2; "Document Reference ID")on table 1173.Count() > 1rather than excluding self, since the primary key is five fields and "more than one owner" is the actual question.