Skip to content

Commit c0b3b80

Browse files
committed
Ensure delete_expired uses writable database.
1 parent 47402b8 commit c0b3b80

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

django_celery_results/managers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ def warn_if_repeatable_read(self):
6868
if isolation == 'REPEATABLE-READ':
6969
warnings.warn(TxIsolationWarning(W_ISOLATION_REP.strip()))
7070

71+
def database_for_write(self):
72+
return router.db_for_write(self.model)
73+
7174
def connection_for_write(self):
72-
return connections[router.db_for_write(self.model)]
75+
return connections[self.database_for_write()]
7376

7477
def connection_for_read(self):
7578
return connections[self.db]
@@ -86,7 +89,7 @@ def get_all_expired(self, expires):
8689

8790
def delete_expired(self, expires):
8891
"""Delete all expired results."""
89-
with transaction.atomic(using=self.db):
92+
with transaction.atomic(using=self.database_for_write()):
9093
raw_delete(queryset=self.get_all_expired(expires))
9194

9295

0 commit comments

Comments
 (0)