Skip to content

Commit db2d4b1

Browse files
committed
Remove parse_uri() per deprecation timeline
1 parent 6d5537c commit db2d4b1

File tree

4 files changed

+1
-167
lines changed

4 files changed

+1
-167
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

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)