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