diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index f98848a9f..7a405d2e2 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -6,6 +6,15 @@ All notable changes to this project are documented in this file. This project adheres to `Semantic Versioning `_. +========== +Unreleased +========== + +Fixed +----- +- Fix error when deleting observer subscription + + =================== 42.2.0 - 2025-01-13 =================== diff --git a/resolwe/observers/models.py b/resolwe/observers/models.py index c2ca8c2a1..f1e4cf169 100644 --- a/resolwe/observers/models.py +++ b/resolwe/observers/models.py @@ -309,16 +309,20 @@ def subscribe( ) self.observers.add(observer) + @transaction.atomic def delete(self): """Delete the given subscription. Delete all observers with no remaining subscriptions. + + This method is marked atomic, so no new subsciptions are added to the observers + we are deleting in the meantime causing IntegrityError. """ - # Find related observers with only one remaining subscription - # (it must be this one) and delete them first. + # First find observers with only this subscription and delete them. Observer.objects.annotate(subs=Count("subscriptions")).filter( subscriptions=self.pk, subs=1 ).delete() + # Now delete the subscription itself. super().delete() @classmethod