Skip to content

Commit 406f04a

Browse files
author
Omer Katz
authored
When using the MongoDB backend, don't cleanup if result_expires is 0 or None. (celery#6462)
Fixes celery#6450.
1 parent 84951b1 commit 406f04a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

celery/backends/mongodb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ def _forget(self, task_id):
248248

249249
def cleanup(self):
250250
"""Delete expired meta-data."""
251+
if not self.expires:
252+
return
253+
251254
self.collection.delete_many(
252255
{'date_done': {'$lt': self.app.now() - self.expires_delta}},
253256
)

t/unit/backends/test_mongodb.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ def test_cleanup(self, mock_get_database):
485485
mock_get_database.assert_called_once_with()
486486
mock_collection.delete_many.assert_called()
487487

488+
self.backend.collections = mock_collection = Mock()
489+
self.backend.expires = None
490+
491+
self.backend.cleanup()
492+
mock_collection.delete_many.assert_not_called()
493+
488494
def test_get_database_authfailure(self):
489495
x = MongoBackend(app=self.app)
490496
x._get_connection = Mock()

0 commit comments

Comments
 (0)