Skip to content

Commit

Permalink
When using the MongoDB backend, don't cleanup if result_expires is 0 …
Browse files Browse the repository at this point in the history
…or None.

Fixes #6450.
  • Loading branch information
thedrow committed Nov 3, 2020
1 parent db35ca1 commit b0f0806
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions celery/backends/mongodb.py
Expand Up @@ -248,6 +248,9 @@ def _forget(self, task_id):

def cleanup(self):
"""Delete expired meta-data."""
if not self.expires:
return

self.collection.delete_many(
{'date_done': {'$lt': self.app.now() - self.expires_delta}},
)
Expand Down
6 changes: 6 additions & 0 deletions t/unit/backends/test_mongodb.py
Expand Up @@ -485,6 +485,12 @@ def test_cleanup(self, mock_get_database):
mock_get_database.assert_called_once_with()
mock_collection.delete_many.assert_called()

self.backend.collections = mock_collection = Mock()
self.backend.expires = None

self.backend.cleanup()
mock_collection.delete_many.assert_not_called()

def test_get_database_authfailure(self):
x = MongoBackend(app=self.app)
x._get_connection = Mock()
Expand Down

0 comments on commit b0f0806

Please sign in to comment.