mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-07 22:25:35 +00:00
Fix Check.lock_and_delete() to gracefully handle already deleted check
This commit is contained in:
parent
9a44ef1571
commit
324fa10ce7
2 changed files with 9 additions and 1 deletions
hc/api
|
@ -346,7 +346,7 @@ class Check(models.Model):
|
|||
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)
|
||||
|
|
|
@ -473,3 +473,11 @@ class CheckModelTestCase(BaseTestCase):
|
|||
# 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()
|
||||
|
|
Loading…
Add table
Reference in a new issue