Skip to content

Commit f8c9528

Browse files
committed
INTPYTHON-759 Deprecate parse_uri()
1 parent d44a82f commit f8c9528

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

django_mongodb_backend/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import copy
22
import time
3+
import warnings
34

45
import django
56
from django.conf import settings
67
from django.core.exceptions import ImproperlyConfigured, ValidationError
78
from django.db.backends.utils import logger
9+
from django.utils.deprecation import RemovedInDjango60Warning
810
from django.utils.functional import SimpleLazyObject
911
from django.utils.text import format_lazy
1012
from django.utils.version import get_version_tuple
@@ -33,6 +35,11 @@ def parse_uri(uri, *, db_name=None, options=None, test=None):
3335
Convert the given uri into a dictionary suitable for Django's DATABASES
3436
setting.
3537
"""
38+
warnings.warn(
39+
'parse_uri() is deprecated. Put the connection string in DATABASES["HOST"] instead.',
40+
RemovedInDjango60Warning,
41+
stacklevel=2,
42+
)
3643
uri = pymongo_parse_uri(uri)
3744
host = None
3845
port = None

docs/internals/deprecation.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,30 @@ Deprecation Timeline
44

55
This document outlines when various pieces of Django MongoDB Backend will be
66
removed or altered in a backward incompatible way, following their deprecation.
7+
8+
6.0
9+
---
10+
11+
.. _parse-uri-deprecation:
12+
13+
``parse_uri()`` will be removed
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
16+
``django_mongodb_backend.utils.parse_uri()`` is deprecated in favor of putting
17+
the connection string in ``DATABASES["HOST"]``.
18+
19+
For example, instead of::
20+
21+
DATABASES = {
22+
"default": django_mongodb_backend.parse_uri("mongodb://localhost:27017/", db_name="db"),
23+
}
24+
25+
use::
26+
27+
DATABASES = {
28+
'default': {
29+
'ENGINE': 'django_mongodb_backend',
30+
'HOST': 'mongodb://localhost:27017/',
31+
'NAME': 'db',
32+
},
33+
}

docs/ref/utils.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ following parts can be considered stable.
1414

1515
.. function:: parse_uri(uri, db_name=None, options=None, test=None)
1616

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+
1723
Parses a MongoDB `connection string`_ into a dictionary suitable for
1824
Django's :setting:`DATABASES` setting.
1925

docs/releases/5.2.x.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ Bug fixes
1717

1818
- ...
1919

20+
Deprecated features
21+
-------------------
22+
23+
- ``django_mongodb_backend.utils.parse_uri()`` is deprecated in favor of
24+
putting the connection string in ``DATABASES["HOST"]``. See
25+
:ref:`the deprecation timeline <parse-uri-deprecation>` for upgrade
26+
instructions.
27+
2028
5.2.1
2129
=====
2230

tests/backend_/utils/test_parse_uri.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import pymongo
44
from django.core.exceptions import ImproperlyConfigured
55
from django.test import SimpleTestCase
6+
from django.test.utils import ignore_warnings
7+
from django.utils.deprecation import RemovedInDjango60Warning
68

79
from django_mongodb_backend import parse_uri
810

911

12+
@ignore_warnings(category=RemovedInDjango60Warning)
1013
class ParseURITests(SimpleTestCase):
1114
def test_simple_uri(self):
1215
settings_dict = parse_uri("mongodb://cluster0.example.mongodb.net/myDatabase")
@@ -105,3 +108,10 @@ def test_invalid_credentials(self):
105108
def test_no_scheme(self):
106109
with self.assertRaisesMessage(pymongo.errors.InvalidURI, "Invalid URI scheme"):
107110
parse_uri("cluster0.example.mongodb.net")
111+
112+
113+
class ParseURIDeprecationTests(SimpleTestCase):
114+
def test_message(self):
115+
msg = 'parse_uri() is deprecated. Put the connection string in DATABASES["HOST"] instead.'
116+
with self.assertRaisesMessage(RemovedInDjango60Warning, msg):
117+
parse_uri("mongodb://cluster0.example.mongodb.net/")

0 commit comments

Comments
 (0)