From 711d7fb53f40156354e2024fe2acd96f9cae4401 Mon Sep 17 00:00:00 2001 From: Allen Wang Date: Mon, 23 Sep 2024 19:45:34 -0700 Subject: [PATCH 1/2] adding check for nullity in related models delete --- safedelete/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/safedelete/models.py b/safedelete/models.py index 30a693a..c534bd8 100644 --- a/safedelete/models.py +++ b/safedelete/models.py @@ -234,8 +234,10 @@ def soft_delete_cascade_policy_action(self, **kwargs) -> Tuple[int, Dict[str, in deleted_counter: Counter = Counter() for related in related_objects(self): if is_safedelete_cls(related.__class__) and not getattr(related, FIELD_NAME): - _, delete_response = related.delete(force_policy=SOFT_DELETE, is_cascade=True, **kwargs) - deleted_counter.update(delete_response) + res = related.delete(force_policy=SOFT_DELETE, is_cascade=True, **kwargs) + if res is not None: + _, delete_response = res + deleted_counter.update(delete_response) # soft-delete the object _, delete_response = self._delete(force_policy=SOFT_DELETE, **kwargs) From 0268e0b067d7fc6574b3c50b194768a50fea8715 Mon Sep 17 00:00:00 2001 From: Allen Wang Date: Fri, 4 Oct 2024 16:44:28 -0700 Subject: [PATCH 2/2] adding check for nullity in queryset delete --- safedelete/queryset.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/safedelete/queryset.py b/safedelete/queryset.py index 5b0c99d..3b78cd0 100644 --- a/safedelete/queryset.py +++ b/safedelete/queryset.py @@ -61,8 +61,10 @@ def delete(self, force_policy: Optional[int] = None) -> Tuple[int, Dict[str, int deleted_counter: Counter = Counter() # TODO: Replace this by bulk update if we can for obj in self.all(): - _, delete_response = obj.delete(force_policy=force_policy) - deleted_counter.update(delete_response) + res = obj.delete(force_policy=force_policy) + if res is not None: + _, delete_response = res + deleted_counter.update(delete_response) self._result_cache = None return sum(deleted_counter.values()), dict(deleted_counter) delete.alters_data = True # type: ignore