Skip to content

Remove parse_uri()'s conn_max_age parameter #301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions django_mongodb_backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def check_django_compatability():
)


def parse_uri(uri, *, db_name=None, conn_max_age=0, test=None):
def parse_uri(uri, *, db_name=None, test=None):
"""
Convert the given uri into a dictionary suitable for Django's DATABASES
setting.
Expand Down Expand Up @@ -56,7 +56,6 @@ def parse_uri(uri, *, db_name=None, conn_max_age=0, test=None):
"USER": uri.get("username"),
"PASSWORD": uri.get("password"),
"OPTIONS": uri.get("options"),
"CONN_MAX_AGE": conn_max_age,
}
if "authSource" not in settings_dict["OPTIONS"] and uri["database"]:
settings_dict["OPTIONS"]["authSource"] = uri["database"]
Expand Down
4 changes: 1 addition & 3 deletions docs/source/ref/utils.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ following parts can be considered stable.
``parse_uri()``
===============

.. function:: parse_uri(uri, db_name=None, conn_max_age=0, test=None)
.. function:: parse_uri(uri, db_name=None, test=None)

Parses a MongoDB `connection string`_ into a dictionary suitable for Django's
:setting:`DATABASES` setting.
Expand All @@ -32,8 +32,6 @@ doesn't specify ``defaultauthdb``.
You can use the parameters to customize the resulting :setting:`DATABASES`
setting:

- Use ``conn_max_age`` to configure :ref:`persistent database connections
<persistent-database-connections>`.
- Use ``test`` to provide a dictionary of settings for test databases in the
format of :setting:`TEST <DATABASE-TEST>`.

Expand Down
3 changes: 3 additions & 0 deletions docs/source/releases/5.2.x.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Backwards incompatible changes
------------------------------

- The minimum supported version of ``pymongo`` is increased from 4.6 to 4.7.
- The ``conn_max_age`` parameter of
:func:`~django_mongodb_backend.utils.parse_uri` is removed because persistent
connections are now used by default.

Bug fixes
---------
Expand Down
4 changes: 0 additions & 4 deletions tests/backend_/utils/test_parse_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ def test_auth_source_in_query_string_overrides_defaultauthdb(self):
self.assertEqual(settings_dict["NAME"], "db")
self.assertEqual(settings_dict["OPTIONS"], {"authSource": "auth"})

def test_conn_max_age(self):
settings_dict = parse_uri("mongodb://localhost/db", conn_max_age=600)
self.assertEqual(settings_dict["CONN_MAX_AGE"], 600)

def test_test_kwarg(self):
settings_dict = parse_uri("mongodb://localhost/db", test={"NAME": "test_db"})
self.assertEqual(settings_dict["TEST"], {"NAME": "test_db"})
Expand Down