File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import ipaddress
19
19
import random
20
+ from importlib .metadata import version
20
21
from typing import TYPE_CHECKING , Any , Optional , Union
21
22
22
- from pymongo .common import CONNECT_TIMEOUT
23
+ from pymongo .common import CONNECT_TIMEOUT , check_for_min_version
23
24
from pymongo .errors import ConfigurationError
24
25
25
26
if TYPE_CHECKING :
@@ -32,6 +33,15 @@ def _have_dnspython() -> bool:
32
33
try :
33
34
import dns # noqa: F401
34
35
36
+ dns_version = version ("dnspython" )
37
+ required_version , is_valid = check_for_min_version (dns_version , "dnspython" )
38
+ if not is_valid :
39
+ raise RuntimeError (
40
+ f"pymongo requires dnspython>={ required_version } , "
41
+ f"found version { dns_version } . "
42
+ "Install a compatible version with pip"
43
+ )
44
+
35
45
return True
36
46
except ImportError :
37
47
return False
@@ -80,6 +90,8 @@ def __init__(
80
90
srv_service_name : str ,
81
91
srv_max_hosts : int = 0 ,
82
92
):
93
+ # Ensure the version of dnspython is compatible.
94
+ _have_dnspython ()
83
95
self .__fqdn = fqdn
84
96
self .__srv = srv_service_name
85
97
self .__connect_timeout = connect_timeout or CONNECT_TIMEOUT
Original file line number Diff line number Diff line change 17
17
18
18
import ipaddress
19
19
import random
20
+ from importlib .metadata import version
20
21
from typing import TYPE_CHECKING , Any , Optional , Union
21
22
22
- from pymongo .common import CONNECT_TIMEOUT
23
+ from pymongo .common import CONNECT_TIMEOUT , check_for_min_version
23
24
from pymongo .errors import ConfigurationError
24
25
25
26
if TYPE_CHECKING :
@@ -32,6 +33,15 @@ def _have_dnspython() -> bool:
32
33
try :
33
34
import dns # noqa: F401
34
35
36
+ dns_version = version ("dnspython" )
37
+ required_version , is_valid = check_for_min_version (dns_version , "dnspython" )
38
+ if not is_valid :
39
+ raise RuntimeError (
40
+ f"pymongo requires dnspython>={ required_version } , "
41
+ f"found version { dns_version } . "
42
+ "Install a compatible version with pip"
43
+ )
44
+
35
45
return True
36
46
except ImportError :
37
47
return False
@@ -80,6 +90,8 @@ def __init__(
80
90
srv_service_name : str ,
81
91
srv_max_hosts : int = 0 ,
82
92
):
93
+ # Ensure the version of dnspython is compatible.
94
+ _have_dnspython ()
83
95
self .__fqdn = fqdn
84
96
self .__srv = srv_service_name
85
97
self .__connect_timeout = connect_timeout or CONNECT_TIMEOUT
You can’t perform that action at this time.
0 commit comments