From a5d8a30b6b8b4d67ec1746f6e3e2bb3c6b994651 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 11 Apr 2025 11:05:37 -0400 Subject: [PATCH] Use persistent connections by default --- django_mongodb_backend/base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/django_mongodb_backend/base.py b/django_mongodb_backend/base.py index e28fdc26..c5fb1ede 100644 --- a/django_mongodb_backend/base.py +++ b/django_mongodb_backend/base.py @@ -165,6 +165,10 @@ def get_connection_params(self): settings_dict = self.settings_dict if not settings_dict["NAME"]: raise ImproperlyConfigured('settings.DATABASES is missing the "NAME" value.') + # Use persistent connections by default, even if the user specifies + # CONN_MAX_AGE=0. (This code has no way to distinguish that case.) + if settings_dict["CONN_MAX_AGE"] == 0: + settings_dict["CONN_MAX_AGE"] = None return { "host": settings_dict["HOST"] or None, "port": int(settings_dict["PORT"] or 27017),