Skip to content

Commit 19d31c7

Browse files
committed
Move IO out of __init__
1 parent 0cbc00f commit 19d31c7

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

pymongo/asynchronous/srv_resolver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ async def _get_srv_response_and_hosts(
133133
) -> tuple[resolver.Answer, list[tuple[str, Any]]]:
134134
results = await self._resolve_uri(encapsulate_errors)
135135

136+
if self.__fqdn == results[0].target.to_text():
137+
raise ConfigurationError(
138+
"Invalid SRV host: return address is identical to SRV hostname"
139+
)
140+
136141
# Construct address tuples
137142
nodes = [
138143
(maybe_decode(res.target.to_text(omit_final_dot=True)), res.port) # type: ignore[attr-defined]

pymongo/synchronous/srv_resolver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ def _get_srv_response_and_hosts(
133133
) -> tuple[resolver.Answer, list[tuple[str, Any]]]:
134134
results = self._resolve_uri(encapsulate_errors)
135135

136+
if self.__fqdn == results[0].target.to_text():
137+
raise ConfigurationError(
138+
"Invalid SRV host: return address is identical to SRV hostname"
139+
)
140+
136141
# Construct address tuples
137142
nodes = [
138143
(maybe_decode(res.target.to_text(omit_final_dot=True)), res.port) # type: ignore[attr-defined]

test/test_uri_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def test_error_when_return_address_does_not_end_with_srv_domain(self):
588588
},
589589
{
590590
"query": "_mongodb._tcp.mongo.local",
591-
"mock_target": "mongo.local",
591+
"mock_target": "foo.mongo.local",
592592
"expected_error": "Invalid SRV host",
593593
},
594594
]

0 commit comments

Comments
 (0)