Skip to content

Commit 79c09ea

Browse files
committed
this might be broken? unsure....
1 parent ead780a commit 79c09ea

File tree

5 files changed

+80
-83
lines changed

5 files changed

+80
-83
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,6 @@ def __init__(
784784
validate=True,
785785
warn=True,
786786
normalize=False,
787-
srv_service_name=srv_service_name,
788787
srv_max_hosts=srv_max_hosts,
789788
)
790789
seeds.update(res["nodelist"])
@@ -836,8 +835,6 @@ def __init__(
836835
_check_options(seeds, opts)
837836

838837
# Username and password passed as kwargs override user info in URI.
839-
username = opts.get("username", username)
840-
password = opts.get("password", password)
841838
self._options = options = ClientOptions(username, password, dbase, opts, _IS_SYNC)
842839

843840
self._default_database_name = dbase
@@ -875,6 +872,15 @@ def __init__(
875872
self._closed = False
876873
self._init_background()
877874

875+
self._for_resolve_uri = {
876+
"username": username,
877+
"password": password,
878+
"dbase": dbase,
879+
"fqdn": fqdn,
880+
"pool_class": pool_class,
881+
"monitor_class": monitor_class,
882+
"condition_class": condition_class,
883+
}
878884
if _IS_SYNC and connect:
879885
self._get_topology() # type: ignore[unused-coroutine]
880886

@@ -890,16 +896,16 @@ def __init__(
890896
# This will be used later if we fork.
891897
AsyncMongoClient._clients[self._topology._topology_id] = self
892898

893-
self._for_resolve_uri = {
894-
"username": username,
895-
"password": password,
896-
"srv_service_name": srv_service_name,
897-
"srv_max_hosts": srv_max_hosts,
898-
"fqdn": fqdn,
899-
"pool_class": pool_class,
900-
"monitor_class": monitor_class,
901-
"condition_class": condition_class,
902-
}
899+
# self._for_resolve_uri = {
900+
# "username": username,
901+
# "password": password,
902+
# "srv_service_name": srv_service_name,
903+
# "srv_max_hosts": srv_max_hosts,
904+
# "fqdn": fqdn,
905+
# "pool_class": pool_class,
906+
# "monitor_class": monitor_class,
907+
# "condition_class": condition_class,
908+
# }
903909

904910
def _resolve_uri(self):
905911
keyword_opts = common._CaseInsensitiveDictionary(self._init_kwargs)
@@ -986,7 +992,7 @@ def _resolve_uri(self):
986992
username = opts.get("username", self._for_resolve_uri["username"])
987993
password = opts.get("password", self._for_resolve_uri["password"])
988994
self._options = ClientOptions(
989-
username, password, self._default_database_name, opts, _IS_SYNC
995+
username, password, self._for_resolve_uri["dbase"], opts, _IS_SYNC
990996
)
991997

992998
self._event_listeners = self._options.pool_options._event_listeners

pymongo/synchronous/mongo_client.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,6 @@ def __init__(
782782
validate=True,
783783
warn=True,
784784
normalize=False,
785-
srv_service_name=srv_service_name,
786785
srv_max_hosts=srv_max_hosts,
787786
)
788787
seeds.update(res["nodelist"])
@@ -834,8 +833,6 @@ def __init__(
834833
_check_options(seeds, opts)
835834

836835
# Username and password passed as kwargs override user info in URI.
837-
username = opts.get("username", username)
838-
password = opts.get("password", password)
839836
self._options = options = ClientOptions(username, password, dbase, opts, _IS_SYNC)
840837

841838
self._default_database_name = dbase
@@ -873,6 +870,15 @@ def __init__(
873870
self._closed = False
874871
self._init_background()
875872

873+
self._for_resolve_uri = {
874+
"username": username,
875+
"password": password,
876+
"dbase": dbase,
877+
"fqdn": fqdn,
878+
"pool_class": pool_class,
879+
"monitor_class": monitor_class,
880+
"condition_class": condition_class,
881+
}
876882
if _IS_SYNC and connect:
877883
self._get_topology() # type: ignore[unused-coroutine]
878884

@@ -888,16 +894,16 @@ def __init__(
888894
# This will be used later if we fork.
889895
MongoClient._clients[self._topology._topology_id] = self
890896

891-
self._for_resolve_uri = {
892-
"username": username,
893-
"password": password,
894-
"srv_service_name": srv_service_name,
895-
"srv_max_hosts": srv_max_hosts,
896-
"fqdn": fqdn,
897-
"pool_class": pool_class,
898-
"monitor_class": monitor_class,
899-
"condition_class": condition_class,
900-
}
897+
# self._for_resolve_uri = {
898+
# "username": username,
899+
# "password": password,
900+
# "srv_service_name": srv_service_name,
901+
# "srv_max_hosts": srv_max_hosts,
902+
# "fqdn": fqdn,
903+
# "pool_class": pool_class,
904+
# "monitor_class": monitor_class,
905+
# "condition_class": condition_class,
906+
# }
901907

902908
def _resolve_uri(self):
903909
keyword_opts = common._CaseInsensitiveDictionary(self._init_kwargs)
@@ -984,7 +990,7 @@ def _resolve_uri(self):
984990
username = opts.get("username", self._for_resolve_uri["username"])
985991
password = opts.get("password", self._for_resolve_uri["password"])
986992
self._options = ClientOptions(
987-
username, password, self._default_database_name, opts, _IS_SYNC
993+
username, password, self._for_resolve_uri["dbase"], opts, _IS_SYNC
988994
)
989995

990996
self._event_listeners = self._options.pool_options._event_listeners

pymongo/uri_parser.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,6 @@ def parse_uri(
427427
validate: bool = True,
428428
warn: bool = False,
429429
normalize: bool = True,
430-
srv_service_name: Optional[str] = None,
431430
srv_max_hosts: Optional[int] = None,
432431
) -> dict[str, Any]:
433432
"""Parse and validate a MongoDB URI.
@@ -526,8 +525,6 @@ def parse_uri(
526525

527526
if opts:
528527
options.update(split_options(opts, validate, warn, normalize))
529-
if srv_service_name is None:
530-
srv_service_name = options.get("srvServiceName", SRV_SERVICE_NAME)
531528
if "@" in host_part:
532529
userinfo, _, hosts = host_part.rpartition("@")
533530
user, passwd = parse_userinfo(userinfo)

test/asynchronous/test_dns.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from pymongo.common import validate_read_preference_tags
3535
from pymongo.errors import ConfigurationError
36-
from pymongo.uri_parser import parse_uri, split_hosts
36+
from pymongo.uri_parser import parse_uri, parse_uri_lookups, split_hosts
3737

3838
_IS_SYNC = False
3939

@@ -110,6 +110,7 @@ async def run_test(self):
110110

111111
if seeds or num_seeds:
112112
result = parse_uri(uri, validate=True)
113+
result.update(parse_uri_lookups(uri, validate=True))
113114
if seeds is not None:
114115
self.assertEqual(sorted(result["nodelist"]), sorted(seeds))
115116
if num_seeds is not None:
@@ -141,13 +142,16 @@ async def run_test(self):
141142
# Our test certs don't support the SRV hosts used in these
142143
# tests.
143144
copts["tlsAllowInvalidHostnames"] = True
144-
145+
print(uri)
146+
print(copts)
145147
client = self.simple_client(uri, **copts)
148+
await client.aconnect()
146149
if client._options.connect:
147150
await client.aconnect()
148151
if num_seeds is not None:
149152
self.assertEqual(len(client._topology_settings.seeds), num_seeds)
150153
if hosts is not None:
154+
print(client.nodes)
151155
await async_wait_until(
152156
lambda: hosts == client.nodes, "match test hosts to client nodes"
153157
)
@@ -162,6 +166,7 @@ async def run_test(self):
162166
else:
163167
try:
164168
parse_uri(uri)
169+
parse_uri_lookups(uri)
165170
except (ConfigurationError, ValueError):
166171
pass
167172
else:
@@ -185,35 +190,24 @@ def create_tests(cls):
185190

186191
class TestParsingErrors(AsyncPyMongoTestCase):
187192
async def test_invalid_host(self):
188-
self.assertRaisesRegex(
189-
ConfigurationError,
190-
"Invalid URI host: mongodb is not",
191-
self.simple_client,
192-
"mongodb+srv://mongodb",
193-
)
194-
self.assertRaisesRegex(
195-
ConfigurationError,
196-
"Invalid URI host: mongodb.com is not",
197-
self.simple_client,
198-
"mongodb+srv://mongodb.com",
199-
)
200-
self.assertRaisesRegex(
201-
ConfigurationError,
202-
"Invalid URI host: an IP address is not",
203-
self.simple_client,
204-
"mongodb+srv://127.0.0.1",
205-
)
206-
self.assertRaisesRegex(
207-
ConfigurationError,
208-
"Invalid URI host: an IP address is not",
209-
self.simple_client,
210-
"mongodb+srv://[::1]",
211-
)
193+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb is not"):
194+
client = self.simple_client("mongodb+srv://mongodb")
195+
await client.aconnect()
196+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb.com is not"):
197+
client = self.simple_client("mongodb+srv://mongodb.com")
198+
await client.aconnect()
199+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"):
200+
client = self.simple_client("mongodb+srv://127.0.0.1")
201+
await client.aconnect()
202+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"):
203+
client = self.simple_client("mongodb+srv://[::1]")
204+
await client.aconnect()
212205

213206

214207
class IsolatedAsyncioTestCaseInsensitive(AsyncIntegrationTest):
215208
async def test_connect_case_insensitive(self):
216209
client = self.simple_client("mongodb+srv://TEST1.TEST.BUILD.10GEN.cc/")
210+
await client.aconnect()
217211
self.assertGreater(len(client.topology_description.server_descriptions()), 1)
218212

219213

test/test_dns.py

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from pymongo.common import validate_read_preference_tags
3535
from pymongo.errors import ConfigurationError
36-
from pymongo.uri_parser import parse_uri, split_hosts
36+
from pymongo.uri_parser import parse_uri, parse_uri_lookups, split_hosts
3737

3838
_IS_SYNC = True
3939

@@ -110,6 +110,7 @@ def run_test(self):
110110

111111
if seeds or num_seeds:
112112
result = parse_uri(uri, validate=True)
113+
result.update(parse_uri_lookups(uri, validate=True))
113114
if seeds is not None:
114115
self.assertEqual(sorted(result["nodelist"]), sorted(seeds))
115116
if num_seeds is not None:
@@ -141,13 +142,16 @@ def run_test(self):
141142
# Our test certs don't support the SRV hosts used in these
142143
# tests.
143144
copts["tlsAllowInvalidHostnames"] = True
144-
145+
print(uri)
146+
print(copts)
145147
client = self.simple_client(uri, **copts)
148+
client._connect()
146149
if client._options.connect:
147150
client._connect()
148151
if num_seeds is not None:
149152
self.assertEqual(len(client._topology_settings.seeds), num_seeds)
150153
if hosts is not None:
154+
print(client.nodes)
151155
wait_until(lambda: hosts == client.nodes, "match test hosts to client nodes")
152156
if num_hosts is not None:
153157
wait_until(
@@ -160,6 +164,7 @@ def run_test(self):
160164
else:
161165
try:
162166
parse_uri(uri)
167+
parse_uri_lookups(uri)
163168
except (ConfigurationError, ValueError):
164169
pass
165170
else:
@@ -183,35 +188,24 @@ def create_tests(cls):
183188

184189
class TestParsingErrors(PyMongoTestCase):
185190
def test_invalid_host(self):
186-
self.assertRaisesRegex(
187-
ConfigurationError,
188-
"Invalid URI host: mongodb is not",
189-
self.simple_client,
190-
"mongodb+srv://mongodb",
191-
)
192-
self.assertRaisesRegex(
193-
ConfigurationError,
194-
"Invalid URI host: mongodb.com is not",
195-
self.simple_client,
196-
"mongodb+srv://mongodb.com",
197-
)
198-
self.assertRaisesRegex(
199-
ConfigurationError,
200-
"Invalid URI host: an IP address is not",
201-
self.simple_client,
202-
"mongodb+srv://127.0.0.1",
203-
)
204-
self.assertRaisesRegex(
205-
ConfigurationError,
206-
"Invalid URI host: an IP address is not",
207-
self.simple_client,
208-
"mongodb+srv://[::1]",
209-
)
191+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb is not"):
192+
client = self.simple_client("mongodb+srv://mongodb")
193+
client._connect()
194+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: mongodb.com is not"):
195+
client = self.simple_client("mongodb+srv://mongodb.com")
196+
client._connect()
197+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"):
198+
client = self.simple_client("mongodb+srv://127.0.0.1")
199+
client._connect()
200+
with self.assertRaisesRegex(ConfigurationError, "Invalid URI host: an IP address is not"):
201+
client = self.simple_client("mongodb+srv://[::1]")
202+
client._connect()
210203

211204

212205
class TestCaseInsensitive(IntegrationTest):
213206
def test_connect_case_insensitive(self):
214207
client = self.simple_client("mongodb+srv://TEST1.TEST.BUILD.10GEN.cc/")
208+
client._connect()
215209
self.assertGreater(len(client.topology_description.server_descriptions()), 1)
216210

217211

0 commit comments

Comments
 (0)