Skip to content

Commit 0d93ec4

Browse files
authored
PYTHON-5573 Require dnspython 2.6.1+ (mongodb#2559)
1 parent 1f308c8 commit 0d93ec4

File tree

6 files changed

+10
-53
lines changed

6 files changed

+10
-53
lines changed

.github/workflows/test-python.yml

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ jobs:
225225
permissions:
226226
contents: read
227227
runs-on: ubuntu-latest
228-
name: Test using minimum dependencies and supported Python
228+
name: Test minimum dependencies and Python
229229
steps:
230230
- uses: actions/checkout@v5
231231
with:
@@ -238,37 +238,10 @@ jobs:
238238
uses: mongodb-labs/drivers-evergreen-tools@master
239239
with:
240240
version: "8.0"
241-
# Async and our test_dns do not support dnspython 1.X, so we don't run async or dns tests here
242241
- name: Run tests
243242
shell: bash
244243
run: |
245244
uv venv
246245
source .venv/bin/activate
247-
uv pip install -e ".[test]" --resolution=lowest-direct
248-
pytest -v test/test_srv_polling.py
249-
250-
test_minimum_for_async:
251-
permissions:
252-
contents: read
253-
runs-on: ubuntu-latest
254-
name: Test async's minimum dependencies and Python
255-
steps:
256-
- uses: actions/checkout@v5
257-
with:
258-
persist-credentials: false
259-
- name: Install uv
260-
uses: astral-sh/setup-uv@b75a909f75acd358c2196fb9a5f1299a9a8868a4 # v5
261-
with:
262-
python-version: '3.9'
263-
- id: setup-mongodb
264-
uses: mongodb-labs/drivers-evergreen-tools@master
265-
with:
266-
version: "8.0"
267-
# The lifetime kwarg we use in srv resolution was added to the async resolver API in dnspython 2.1.0
268-
- name: Run tests
269-
shell: bash
270-
run: |
271-
uv venv
272-
source .venv/bin/activate
273-
uv pip install -e ".[test]" --resolution=lowest-direct dnspython==2.1.0 --force-reinstall
246+
uv pip install -e ".[test]" --resolution=lowest-direct --force-reinstall
274247
pytest -v test/test_srv_polling.py test/test_dns.py test/asynchronous/test_srv_polling.py test/asynchronous/test_dns.py

doc/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PyMongo 4.16 brings a number of changes including:
99
- Removed invalid documents from :class:`bson.errors.InvalidDocument` error messages as
1010
doing so may leak sensitive user data.
1111
Instead, invalid documents are stored in :attr:`bson.errors.InvalidDocument.document`.
12+
- PyMongo now requires ``dnspython>=2.6.1``, since ``dnspython`` 1.0 is no longer maintained and is incompatible with
13+
Python 3.10+. The minimum version is ``2.6.1`` to account for `CVE-2023-29483 <https://www.cve.org/CVERecord?id=CVE-2023-29483>`_.
1214
- Removed support for Eventlet.
1315
Eventlet is actively being sunset by its maintainers and has compatibility issues with PyMongo's dnspython dependency.
1416

pymongo/asynchronous/srv_resolver.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@ async def _resolve(*args: Any, **kwargs: Any) -> resolver.Answer:
5858
if _IS_SYNC:
5959
from dns import resolver
6060

61-
if hasattr(resolver, "resolve"):
62-
# dnspython >= 2
63-
return resolver.resolve(*args, **kwargs)
64-
# dnspython 1.X
65-
return resolver.query(*args, **kwargs)
61+
return resolver.resolve(*args, **kwargs)
6662
else:
6763
from dns import asyncresolver
6864

69-
if hasattr(asyncresolver, "resolve"):
70-
# dnspython >= 2
71-
return await asyncresolver.resolve(*args, **kwargs) # type:ignore[return-value]
72-
raise ConfigurationError(
73-
"Upgrade to dnspython version >= 2.0 to use AsyncMongoClient with mongodb+srv:// connections."
74-
)
65+
return await asyncresolver.resolve(*args, **kwargs) # type:ignore[return-value]
7566

7667

7768
_INVALID_HOST_MSG = (

pymongo/synchronous/srv_resolver.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,11 @@ def _resolve(*args: Any, **kwargs: Any) -> resolver.Answer:
5858
if _IS_SYNC:
5959
from dns import resolver
6060

61-
if hasattr(resolver, "resolve"):
62-
# dnspython >= 2
63-
return resolver.resolve(*args, **kwargs)
64-
# dnspython 1.X
65-
return resolver.query(*args, **kwargs)
61+
return resolver.resolve(*args, **kwargs)
6662
else:
6763
from dns import asyncresolver
6864

69-
if hasattr(asyncresolver, "resolve"):
70-
# dnspython >= 2
71-
return asyncresolver.resolve(*args, **kwargs) # type:ignore[return-value]
72-
raise ConfigurationError(
73-
"Upgrade to dnspython version >= 2.0 to use MongoClient with mongodb+srv:// connections."
74-
)
65+
return asyncresolver.resolve(*args, **kwargs) # type:ignore[return-value]
7566

7667

7768
_INVALID_HOST_MSG = (

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dnspython>=1.16.0,<3.0.0
1+
dnspython>=2.6.1,<3.0.0

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)