From c7daadfb18d879a8abe8b404b3e25c2e3350b17d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 15 Sep 2020 12:53:02 +0200 Subject: [PATCH] core: fix logic error in expired models cleanup --- passbook/core/tasks.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/passbook/core/tasks.py b/passbook/core/tasks.py index 04d501a14..16470291e 100644 --- a/passbook/core/tasks.py +++ b/passbook/core/tasks.py @@ -1,4 +1,5 @@ """passbook core tasks""" +from django.utils.timezone import now from structlog import get_logger from passbook.core.models import ExpiringModel @@ -12,5 +13,10 @@ def clean_expired_models(): """Remove expired objects""" for cls in ExpiringModel.__subclasses__(): cls: ExpiringModel - amount, _ = cls.filter_not_expired().delete() + amount, _ = ( + cls.objects.all() + .exclude(expiring=False) + .exclude(expiring=True, expires__gt=now()) + .delete() + ) LOGGER.debug("Deleted expired models", model=cls, amount=amount)