From c0b3b8037f216cac2659d0002c98ad4ceef6fdf2 Mon Sep 17 00:00:00 2001 From: Jack Linke Date: Mon, 16 Jan 2023 13:21:48 -0500 Subject: [PATCH] Ensure `delete_expired` uses writable database. --- django_celery_results/managers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/django_celery_results/managers.py b/django_celery_results/managers.py index 8cb15068..d0332c3d 100644 --- a/django_celery_results/managers.py +++ b/django_celery_results/managers.py @@ -68,8 +68,11 @@ def warn_if_repeatable_read(self): if isolation == 'REPEATABLE-READ': warnings.warn(TxIsolationWarning(W_ISOLATION_REP.strip())) + def database_for_write(self): + return router.db_for_write(self.model) + def connection_for_write(self): - return connections[router.db_for_write(self.model)] + return connections[self.database_for_write()] def connection_for_read(self): return connections[self.db] @@ -86,7 +89,7 @@ def get_all_expired(self, expires): def delete_expired(self, expires): """Delete all expired results.""" - with transaction.atomic(using=self.db): + with transaction.atomic(using=self.database_for_write()): raw_delete(queryset=self.get_all_expired(expires))