Skip to content

Commit f1e1d44

Browse files
committed
Get the port from nodelist
1 parent 1161948 commit f1e1d44

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

django_mongodb/__init__.py

Lines changed: 1 addition & 1 deletion
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
5+
from .utils import check_django_compatability, parse
66

77
check_django_compatability()
88

django_mongodb/utils.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,20 @@ def check_django_compatability():
2828

2929
def parse(uri):
3030
uri = parse_uri(uri)
31+
32+
# If fqdn is None then this is not a SRV URI, so we need to extract the port
33+
# from the first node in the nodelist.
34+
port = None
35+
if uri["fqdn"] is None:
36+
if "nodelist" in uri and isinstance(uri["nodelist"], list) and len(uri["nodelist"]) > 0:
37+
first_node = uri["nodelist"][0]
38+
if isinstance(first_node, tuple) and len(first_node) > 1 and isinstance(first_node[1], int):
39+
port = first_node[1]
40+
3141
return {
3242
"ENGINE": "django_mongodb",
3343
"HOST": uri["fqdn"] or None,
44+
"PORT": port,
3445
"USERNAME": uri.get("username"),
3546
"PASSWORD": uri.get("password"),
3647
}

0 commit comments

Comments
 (0)