core: fix logic error in expired models cleanup

This commit is contained in:
Jens Langhammer 2020-09-15 12:53:02 +02:00
parent 683968c96e
commit c7daadfb18
1 changed files with 7 additions and 1 deletions

View File

@ -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)