From 24399482495a03ec4839c144487376471afaf893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Mon, 16 Nov 2026 17:41:49 -0300 Subject: [PATCH] fix: one file the worker may not delete no longer stops the cleanup of every other file CI run 318 failed in retention_test: an expired upload outside the storage policy's prefixes (originals/, videos/) made delete_object raise AccessDenied, and the cleanup stopped there on every tick, so no file behind it was ever deleted. The worker now logs it as an error (so it reaches Sentry), tries that file again a day later and goes on with the rest; retention_test covers it. The test fixtures that wrote keys under test/, machine-test/, machine-log-test/ and reset-test/ now use originals/, where the worker may delete them. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/worker.py | 12 +++++++++++- tests/launch_reset_test.py | 2 +- tests/machine_log_test.py | 2 +- tests/machine_pull_test.py | 2 +- tests/order_actions_test.py | 2 +- tests/retention_test.py | 11 +++++++++++ tests/users_test.py | 4 ++-- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/app/worker.py b/app/worker.py index 259efee..d666575 100644 --- a/app/worker.py +++ b/app/worker.py @@ -6,6 +6,7 @@ import threading import time from http.server import BaseHTTPRequestHandler, HTTPServer import psycopg +from botocore.exceptions import ClientError from psycopg.types.json import Jsonb from . import mail, observability, unpaid from .adapters import FakeTiny, LocalS3Storage, require_runtime @@ -40,7 +41,16 @@ def cleanup(): AND (expires_at<=now() OR (NOT complete AND created_atnow() AS later FROM dtf_local.uploads WHERE id=%s',(denied,)).fetchone() + assert not row['purged_at'] and row['later'],row + c.execute('DELETE FROM dtf_local.uploads WHERE id=%s',(denied,)) try:storage.size(f'originals/{ids[0]}');raise AssertionError('Expired bytes still exist') except ClientError as exc:assert exc.response['ResponseMetadata']['HTTPStatusCode']==404 assert storage.size(f'originals/{ids[1]}')==len(b'LOCAL RETENTION TEST') diff --git a/tests/users_test.py b/tests/users_test.py index a949ac1..cab9276 100644 --- a/tests/users_test.py +++ b/tests/users_test.py @@ -389,7 +389,7 @@ def run(): upload = uuid4() c.execute('''INSERT INTO dtf_local.uploads(id,owner,name,size,object_key,multipart_id,complete, expires_at,scan_state) VALUES(%s,%s,'final.pdf',1,%s,'m',true,now()+interval '20 days','clean')''', - (upload, owner, f'test/{upload}')) + (upload, owner, f'originals/test-{upload}')) c.execute('''INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by) VALUES(%s,%s,%s,0,'final','ok','t')''', (uuid4(), oid, upload)) c.execute("UPDATE dtf_local.orders SET state='tra', machine_id=%s, machine_chosen=true WHERE id=%s", @@ -453,7 +453,7 @@ def run(): upload = uuid4() c.execute('''INSERT INTO dtf_local.uploads(id,owner,name,size,object_key,multipart_id,complete, expires_at,scan_state) VALUES(%s,%s,'final.pdf',1,%s,'m',true,now()+interval '20 days','clean')''', - (upload, owner, f'test/{upload}')) + (upload, owner, f'originals/test-{upload}')) c.execute('''INSERT INTO dtf_local.order_files(id,order_id,upload_id,item_index,kind,note,created_by) VALUES(%s,%s,%s,0,'final','ok','t')''', (uuid4(), oid, upload)) c.execute("UPDATE dtf_local.orders SET state='tra', machine_id=%s, machine_chosen=true WHERE id=%s",