Repository navigation
fix(images): only delete an image object once no camera, pose or detection uses its key - #734
Conversation
… other rows still use
…ction uses its key
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #734 +/- ##
==========================================
+ Coverage 95.18% 95.33% +0.14%
==========================================
Files 60 61 +1
Lines 3407 3428 +21
==========================================
+ Hits 3243 3268 +25
+ Misses 164 160 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks, this is the right fix and the tests are solid. Two things on
Minor: |
…es on detection deletion
… uses its key A failed object deletion now only logs a warning on a connection error too, and on a bucket that can't be reached before it is cached.
|
All three are in, in
I also ran Three things I left out, tell me if you want any of them here:
|
|
CI note: Edit: it passed on |
# Conflicts: # src/app/api/api_v1/endpoints/detections.py
MateoLostanlen
left a comment
There was a problem hiding this comment.
Hi @Adelagric, thanks for the PR!
All three points are in, and the crop handling looks good. Catching ValueError too makes sense.
- I merged main into your branch to fix the import conflict in detections.py (#673 switched to compute_overlap_async).
- (nit) Agreed on leaving the crop_bucket_key index and to_thread for a follow-up PR. The admin delete route is rare, so it can wait.
CI is green, merging.
Fixes #733.
PATCH /cameras/image,PATCH /poses/{pose_id}/imageandDELETE /detections/{detection_id}now update the row first. They then delete the old S3 object only if no camera (last_image), pose (image) or detection (bucket_key) still references its key. The check isdelete_unreferenced_imageinservices/images.py. It extends to all three tables the check thatDELETE /detections/{detection_id}already made among detections.I first considered prefixing camera and pose keys, as
crop_does. That stops new collisions, but keys already shared in the database have no prefix, so their first replacement after deploy would still delete them.Tests (
test_cameras.py,test_poses.py,test_detections.py)mainand pass here:test_update_pose_image_twicenow also asserts that the object exists.Full suite: 735 passed, 1 skipped.
ruff check,ruff format --checkandty checkare clean. Each of these changes makes at least one test fail: removing any of the three reference checks, always or never deleting, reading the key after the update, or dropping the error handling.Not changed
DELETE /detections/{detection_id}deletescrop_bucket_keywithout checking.PATCHrequests on the same camera or pose can still race between the check and the delete. The window is narrower than onmain, which always deletes.cameras.last_imageandposes.imagehave no index, so the check scans those two tables. They are small, and the check runs once per image update.