Skip to content

Commit 1519e0f

Browse files
committed
fix name
1 parent 05ba445 commit 1519e0f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

django_mongodb/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def parse_uri(uri, conn_max_age=0, conn_health_checks=False, test=None):
3434
uri = parse_uri_mongo(uri)
3535
host = None
3636
port = None
37+
name = uri["database"]
38+
3739
if uri["fqdn"] is not None:
3840
# If the fqdn is present, this is a SRV URI and the host is the fqdn.
3941
host = f"mongodb+srv://{uri['fqdn']}"
@@ -45,7 +47,6 @@ def parse_uri(uri, conn_max_age=0, conn_health_checks=False, test=None):
4547
host = ",".join([f"{host}:{port}" for host, port in nodelist])
4648
settings_dict = {
4749
"ENGINE": "django_mongodb",
48-
"NAME": uri["database"],
4950
"HOST": host,
5051
"PORT": port,
5152
"USER": uri.get("username"),
@@ -54,6 +55,8 @@ def parse_uri(uri, conn_max_age=0, conn_health_checks=False, test=None):
5455
"CONN_MAX_AGE": conn_max_age,
5556
"CONN_HEALTH_CHECKS": conn_health_checks,
5657
}
58+
if name:
59+
settings_dict["NAME"] = name
5760
if test:
5861
settings_dict["TEST"] = test
5962
return settings_dict

tests/utils_/test_parse_uri.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def test_simple_uri(self, mock_resolver):
2727
def test_no_database(self, mock_resolver):
2828
settings_dict = parse_uri("mongodb://cluster0.example.mongodb.net/")
2929
self.assertEqual(settings_dict["ENGINE"], "django_mongodb")
30-
self.assertIsNone(settings_dict["NAME"])
3130
self.assertEqual(settings_dict["HOST"], "cluster0.example.mongodb.net")
31+
self.assertFalse("NAME" in settings_dict)
3232

3333
@patch("dns.resolver.resolve")
3434
def test_srv_uri_with_options(self, mock_resolver):

0 commit comments

Comments
 (0)