Skip to content

Commit

Permalink
Fix Check.lock_and_delete() to gracefully handle already deleted check
Browse files Browse the repository at this point in the history
  • Loading branch information
cuu508 committed Jun 20, 2024
1 parent 9a44ef1 commit 324fa10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def lock_and_delete(self) -> None:
in the process of deletion.
"""
with transaction.atomic():
Check.objects.select_for_update().get(id=self.id).delete()
Check.objects.select_for_update().filter(id=self.id).delete()

def assign_all_channels(self) -> None:
channels = Channel.objects.filter(project=self.project)
Expand Down
8 changes: 8 additions & 0 deletions hc/api/tests/test_check_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,11 @@ def test_get_status_handles_autumn_dst_transition(self) -> None:
# The next expected run time is at 2023-10-29 01:15 UTC, so the check
# should still be up for 10 minutes:
self.assertEqual(check.get_status(), "up")

def test_lock_and_delete_handles_already_deleted_checks(self) -> None:
check = Check.objects.create(project=self.project)
same_check = Check.objects.get(id=check.id)
check.delete()

# lock_and_delete should handle an already deleted check gracefully:
same_check.lock_and_delete()

0 comments on commit 324fa10

Please sign in to comment.