♻️(backend) delete file for not ready items

The process_item_deletion task was deleting the file on storage only
when the upload_state was ready. We have case, in the upload_ended
viewset action where we want to delete it before changing the
upload_state status. We decided to not check the status anymore.
This commit is contained in:
Manuel Raynaud
2026-01-09 10:43:56 +01:00
parent d7eccd766f
commit ecdd68f43b
2 changed files with 1 additions and 16 deletions
+1 -4
View File
@@ -34,10 +34,7 @@ def process_item_deletion(item_id):
logger.error("To process an item deletion, it must be hard deleted first.")
return
if (
item.type == ItemTypeChoices.FILE
and item.upload_state == ItemUploadStateChoices.READY
):
if item.type == ItemTypeChoices.FILE:
logger.info("Deleting file %s", item.file_key)
default_storage.delete(item.file_key)
@@ -36,22 +36,10 @@ def test_process_item_deletion_item_does_not_exist(caplog):
assert "Item 1 does not exist" in caplog.records[0].message
def test_process_item_deletion_item_file_is_not_ready():
"""Test the process deletion task when the item file is not ready."""
item = factories.ItemFactory(type=models.ItemTypeChoices.FILE)
item.soft_delete()
item.hard_delete()
process_item_deletion(item.id)
assert not models.Item.objects.filter(id=item.id).exists()
def test_process_item_deletion_item_file_is_ready():
"""Test the process deletion task when the item file is ready."""
item = factories.ItemFactory(
type=models.ItemTypeChoices.FILE,
update_upload_state=models.ItemUploadStateChoices.READY,
filename="foo.txt",
)
item.soft_delete()