Skip to content

Commit cbd36b5

Browse files
committed
Remove parse_uri() per deprecation timeline
1 parent 01d1bce commit cbd36b5

File tree

9 files changed

+8
-212
lines changed

9 files changed

+8
-212
lines changed

django_mongodb_backend/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Check Django compatibility before other imports which may fail if the
44
# wrong version of Django is installed.
5-
from .utils import check_django_compatability, parse_uri
5+
from .utils import check_django_compatability
66

77
check_django_compatability()
88

@@ -15,8 +15,6 @@
1515
from .lookups import register_lookups # noqa: E402
1616
from .query import register_nodes # noqa: E402
1717

18-
__all__ = ["parse_uri"]
19-
2018
register_aggregates()
2119
register_checks()
2220
register_expressions()

django_mongodb_backend/utils.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import copy
22
import time
3-
import warnings
43

54
import django
65
from django.conf import settings
76
from django.core.exceptions import ImproperlyConfigured, ValidationError
87
from django.db.backends.utils import logger
9-
from django.utils.deprecation import RemovedInDjango60Warning
108
from django.utils.functional import SimpleLazyObject
119
from django.utils.text import format_lazy
1210
from django.utils.version import get_version_tuple
13-
from pymongo.uri_parser import parse_uri as pymongo_parse_uri
1411

1512

1613
def check_django_compatability():
@@ -30,50 +27,6 @@ def check_django_compatability():
3027
)
3128

3229

33-
def parse_uri(uri, *, db_name=None, options=None, test=None):
34-
"""
35-
Convert the given uri into a dictionary suitable for Django's DATABASES
36-
setting.
37-
"""
38-
warnings.warn(
39-
'parse_uri() is deprecated. Put the connection string in DATABASES["HOST"] instead.',
40-
RemovedInDjango60Warning,
41-
stacklevel=2,
42-
)
43-
uri = pymongo_parse_uri(uri)
44-
host = None
45-
port = None
46-
if uri["fqdn"]:
47-
# This is a SRV URI and the host is the fqdn.
48-
host = f"mongodb+srv://{uri['fqdn']}"
49-
else:
50-
nodelist = uri.get("nodelist")
51-
if len(nodelist) == 1:
52-
host, port = nodelist[0]
53-
elif len(nodelist) > 1:
54-
host = ",".join([f"{host}:{port}" for host, port in nodelist])
55-
db_name = db_name or uri["database"]
56-
if not db_name:
57-
raise ImproperlyConfigured("You must provide the db_name parameter.")
58-
opts = uri.get("options")
59-
if options:
60-
opts.update(options)
61-
settings_dict = {
62-
"ENGINE": "django_mongodb_backend",
63-
"NAME": db_name,
64-
"HOST": host,
65-
"PORT": port,
66-
"USER": uri.get("username"),
67-
"PASSWORD": uri.get("password"),
68-
"OPTIONS": opts,
69-
}
70-
if "authSource" not in settings_dict["OPTIONS"] and uri["database"]:
71-
settings_dict["OPTIONS"]["authSource"] = uri["database"]
72-
if test:
73-
settings_dict["TEST"] = test
74-
return settings_dict
75-
76-
7730
def prefix_validation_error(error, prefix, code, params):
7831
"""
7932
Prefix a validation error message while maintaining the existing

docs/intro/configure.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ If you have a connection string, you can provide it like this::
122122
.. versionchanged:: 5.2.1
123123

124124
Support for the connection string in ``"HOST"`` was added. Previous
125-
versions recommended using :func:`~django_mongodb_backend.utils.parse_uri`.
125+
versions recommended using ``django_mongodb_backend.utils.parse_uri()``.
126126

127127
Alternatively, you can separate the connection string so that your settings
128128
look more like what you usually see with Django. This constructs a

docs/ref/utils.rst

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,4 @@ This document covers the public API parts of ``django_mongodb_backend.utils``.
99
Most of the module's contents are designed for internal use and only the
1010
following parts can be considered stable.
1111

12-
``parse_uri()``
13-
===============
14-
15-
.. function:: parse_uri(uri, db_name=None, options=None, test=None)
16-
17-
.. deprecated:: 5.2.2
18-
19-
``parse_uri()`` is deprecated in favor of putting the connection string
20-
in ``DATABASES["HOST"]``. See :ref:`the deprecation timeline
21-
<parse-uri-deprecation>` for upgrade instructions.
22-
23-
Parses a MongoDB `connection string`_ into a dictionary suitable for
24-
Django's :setting:`DATABASES` setting.
25-
26-
.. _connection string: https://www.mongodb.com/docs/manual/reference/connection-string/
27-
28-
Example::
29-
30-
import django_mongodb_backend
31-
32-
MONGODB_URI = "mongodb+srv://my_user:my_password@cluster0.example.mongodb.net/defaultauthdb?retryWrites=true&w=majority&tls=false"
33-
DATABASES["default"] = django_mongodb_backend.parse_uri(MONGODB_URI, db_name="example")
34-
35-
You must specify ``db_name`` (the :setting:`NAME` of your database) if the
36-
URI doesn't specify ``defaultauthdb``.
37-
38-
You can use the parameters to customize the resulting :setting:`DATABASES`
39-
setting:
40-
41-
- Use ``options`` to provide a dictionary of parameters to
42-
:class:`~pymongo.mongo_client.MongoClient`. These will be merged with
43-
(and, in the case of duplicates, take precedence over) any options
44-
specified in the URI.
45-
46-
- Use ``test`` to provide a dictionary of settings for test databases in
47-
the format of :setting:`TEST <DATABASE-TEST>`.
48-
49-
But for maximum flexibility, construct :setting:`DATABASES` manually as
50-
described in :ref:`configuring-databases-setting`.
12+
(Currently there is nothing.)

docs/releases/5.0.x.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Django MongoDB Backend 5.0.x
1616
<django:persistent-database-connections>`.
1717
- Added :doc:`async <django:topics/async>` support.
1818
- Added the ``db_name`` parameter to
19-
:func:`~django_mongodb_backend.utils.parse_uri`.
19+
``django_mongodb_backend.utils.parse_uri()``.
2020
- Added ``django_mongodb_backend.routers.MongoRouter`` to allow
2121
:djadmin:`dumpdata` to ignore embedded models. See
2222
:ref:`configuring-database-routers-setting`.

docs/releases/5.1.x.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Django MongoDB Backend 5.1.x
6161
<django:persistent-database-connections>`.
6262
- Added :doc:`async <django:topics/async>` support.
6363
- Added the ``db_name`` parameter to
64-
:func:`~django_mongodb_backend.utils.parse_uri`.
64+
``django_mongodb_backend.utils.parse_uri()``.
6565
- Added ``django_mongodb_backend.routers.MongoRouter`` to allow
6666
:djadmin:`dumpdata` to ignore embedded models. See
6767
:ref:`configuring-database-routers-setting`.

docs/releases/5.2.x.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ New features
9595

9696
- Allowed :ref:`specifying the MongoDB connection string
9797
<configuring-databases-setting>` in ``DATABASES["HOST"]``, eliminating the
98-
need to use :func:`~django_mongodb_backend.utils.parse_uri` to configure the
98+
need to use ``django_mongodb_backend.utils.parse_uri()`` to configure the
9999
:setting:`DATABASES` setting.
100100

101101
Bug fixes
@@ -144,7 +144,7 @@ New features
144144
- Added support for :doc:`Atlas Search queries </ref/models/search>`.
145145
- Added subquery support for :class:`~.fields.EmbeddedModelArrayField`.
146146
- Added the ``options`` parameter to
147-
:func:`~django_mongodb_backend.utils.parse_uri`.
147+
``django_mongodb_backend.utils.parse_uri()``.
148148
- Added support for :ref:`database transactions <transactions>`.
149149
- Added :class:`~.fields.PolymorphicEmbeddedModelField` and
150150
:class:`~.fields.PolymorphicEmbeddedModelArrayField` for storing a model
@@ -231,7 +231,7 @@ Backwards incompatible changes
231231

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

237237
Bug fixes

tests/backend_/utils/__init__.py

Whitespace-only changes.

tests/backend_/utils/test_parse_uri.py

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)