Deleting an attachment does not delete the document in the repository

HI @VonRafaelR16606415

Few questions from my end

  1. What is the version of Pega you are using ?
  2. Is the storage defaulted to Pega DB or an external repository ?

For the error you are encountering you can refer to the below PDN Docs article

Below is the same error mentioned in the documentation.

Attachment Upload Behavior in Pega Constellation

1. POST /attachments/upload

When an attachment is uploaded using the POST /attachments/upload API (for example, during case creation in a form), Pega first creates a temporary attachment instance.

  • The API returns a unique attachment ID to the client.
  • At this stage, the attachment is stored as an instance of Data-WorkAttach-File-Temp in the pegadata.pc_data_file_temp table.
  • This temporary attachment does not yet have a Link-Attachment relationship with a case, so it is effectively an orphan attachment until the case is created or updated.

This behavior is independent of the configured attachment storage option:

  • Database storage – the file content is stored in the Pega database.
  • Repository storage – the file content is stored in the configured external repository.

In both scenarios, a temporary attachment record is created first.

If the user cancels the operation (for example, cancels case creation, delete action):

  • The temporary attachment remains in the temp table.
  • Pega automatically cleans up the temporary attachment after ~2 hours (Did not verify this but hope it works that way)
  • If the storage option is repository, the file is also removed from the repository during the same cleanup process. There were some fixes done in v25.1.2 patch regarding this cleanup which i have to check more in detail.


2. POST /api/v1/cases – Case Creation or Save

When the case creation API (POST /api/v1/cases) is invoked:

  • The temporary attachment ID returned from the upload API is passed to Pega.
  • Pega links the attachment to the case during case creation or save.
  • Once the case transaction is committed, the following happens:
    • The record in pegadata.pc_data_file_temp is deleted.
    • A permanent attachment instance of class Data-WorkAttach-File is created in the pegadata.pc_data_workattach table.

Again, this occurs regardless of the storage option configured:

  • Database storage → file content stored in the Pega database.

  • Repository storage → the attachment metadata is stored in Pega, while the actual file content is stored in the external repository.

Hope this helps

Regards

JC