Skip to content

FileExplorer: re-uploading a deleted file's content fails on the MD5 unique index #260

Open

Description

@duguankui

Problem

After a file is deleted, uploading a file with the same bytes to the same container always fails with a unique-constraint violation. Over HTTP this surfaces as a 500. Over MCP it comes back as kind: unknown, "An internal error occurred".

SQLite Error 19: 'UNIQUE constraint failed: FeFileDescriptors.ContainerName, FeFileDescriptors.Md5'

Found during an end-to-end MCP run against the Site host: upload a.png → delete it → upload a.png again.

Cause

FileDescriptor is soft-deleted (IDeletionAuditedObject + IsDeleted), but the content-dedup unique indexes do not exclude deleted rows:

  • EF Core (FileExplorerDbContextModelCreatingExtensions):
    • (ContainerName, Md5) filtered on TenantId IS NULL AND Md5 <> ''
    • (TenantId, ContainerName, Md5) filtered on TenantId IS NOT NULL AND Md5 <> ''
  • MongoDB (FileExplorerMongoDbContextExtensions): (TenantId, ContainerName, Md5), unique, with partial filter Md5 > ''.

Meanwhile the dedup lookup (FindByMd5Async / Md5ExistsAsync) runs under ABP's soft-delete data filter, so it cannot see the deleted row. It finds nothing, the manager inserts a new descriptor with the same MD5, and the index rejects it. The deleted row keeps its MD5 slot for good.

Options

  1. Exclude deleted rows from the indexes: add IsDeleted = 0 (EF) / IsDeleted: false (Mongo partial filter). This is the smallest semantic change. However, it alters an index that consuming hosts own the migrations for (EF), and the Mongo index has to be dropped and recreated, as RemoveLegacyMd5Index already does for the previous shape. Needs a CHANGELOG migration note.
  2. Let dedup see soft-deleted rows, with the soft-delete filter disabled, and revive or re-point to the existing blob. This avoids an index change, but ties dedup to deleted data and to whether the blob still exists (the reference/orphan rules in the file-storing invariants §3–§4).
  3. Hard-delete descriptors. This drops the soft-delete audit trail, so it is probably not wanted.

Option 1 looks right. Whatever the fix, invariant §3 also applies here: the database constraint is the arbiter, so a concurrent duplicate upload should be turned into a business error rather than a raw DbUpdateException.

Not fixed in the MCP work (#254, #259). Since #259, an MCP client at least gets a complete error response and the cause is logged.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmodule: blob-storingblob-storing/ (Dignite.Abp.BlobStoring.*)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions