Skip to content

Commit 477217f

Browse files
blink1073NoahStapplpulley
authored
[TASK]-[PYTHON-5623]: [v4.15] Change with_transaction callback return type to Awaitable (#2612)
Co-authored-by: Noah Stapp <noah.stapp@mongodb.com> Co-authored-by: Logan Pulley <logan@pulley.host>
1 parent f3ea373 commit 477217f

File tree

7 files changed

+53
-5
lines changed

7 files changed

+53
-5
lines changed

.github/workflows/dist.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100

101101
make_sdist:
102102
name: Make SDist
103-
runs-on: macos-13
103+
runs-on: macos-14
104104
steps:
105105
- uses: actions/checkout@v5
106106
with:

doc/changelog.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
Changelog
22
=========
33

4+
Changes in Version 4.15.4 (2025/11/11)
5+
--------------------------------------
6+
7+
Version 4.15.4 is a bug fix release.
8+
9+
- Relaxed the callback type of :meth:`~pymongo.asynchronous.client_session.AsyncClientSession.with_transaction` to allow the broader Awaitable type rather than only Coroutine objects.
10+
- Added the missing Python 3.14 trove classifier to the package metadata.
11+
12+
Issues Resolved
13+
...............
14+
15+
See the `PyMongo 4.15.4 release notes in JIRA`_ for the list of resolved issues
16+
in this release.
17+
18+
.. _PyMongo 4.15.4 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=47237
19+
420
Changes in Version 4.15.3 (2025/10/07)
521
--------------------------------------
622

doc/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ work with MongoDB from Python.
2222
Getting Help
2323
------------
2424
If you're having trouble or have questions about PyMongo, ask your question on
25-
our `MongoDB Community Forum <https://www.mongodb.com/community/forums/tag/python>`_.
25+
one of the platforms listed on `Technical Support <https://www.mongodb.com/docs/manual/support/>`_.
2626
You may also want to consider a
2727
`commercial support subscription <https://support.mongodb.com/welcome>`_.
2828
Once you get an answer, it'd be great if you could work it back into this
@@ -37,7 +37,7 @@ project.
3737

3838
Feature Requests / Feedback
3939
---------------------------
40-
Use our `feedback engine <https://feedback.mongodb.com/forums/924286-drivers>`_
40+
Use our `feedback engine <https://feedback.mongodb.com/?category=7548141816650747033>`_
4141
to send us feature requests and general feedback about PyMongo.
4242

4343
Contributing

pymongo/asynchronous/client_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@
143143
TYPE_CHECKING,
144144
Any,
145145
AsyncContextManager,
146+
Awaitable,
146147
Callable,
147-
Coroutine,
148148
Mapping,
149149
MutableMapping,
150150
NoReturn,
@@ -600,7 +600,7 @@ def _inherit_option(self, name: str, val: _T) -> _T:
600600

601601
async def with_transaction(
602602
self,
603-
callback: Callable[[AsyncClientSession], Coroutine[Any, Any, _T]],
603+
callback: Callable[[AsyncClientSession], Awaitable[_T]],
604604
read_concern: Optional[ReadConcern] = None,
605605
write_concern: Optional[WriteConcern] = None,
606606
read_preference: Optional[_ServerMode] = None,

test/asynchronous/test_transactions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Execute Transactions Spec tests."""
1616
from __future__ import annotations
1717

18+
import asyncio
1819
import sys
1920
from io import BytesIO
2021
from test.asynchronous.utils_spec_runner import AsyncSpecRunner
@@ -469,6 +470,17 @@ async def callback2(session):
469470
async with self.client.start_session() as s:
470471
self.assertEqual(await s.with_transaction(callback2), "Foo")
471472

473+
@async_client_context.require_transactions
474+
@async_client_context.require_async
475+
async def test_callback_awaitable_no_coroutine(self):
476+
def callback(_):
477+
future = asyncio.Future()
478+
future.set_result("Foo")
479+
return future
480+
481+
async with self.client.start_session() as s:
482+
self.assertEqual(await s.with_transaction(callback), "Foo")
483+
472484
@async_client_context.require_transactions
473485
async def test_callback_not_retried_after_timeout(self):
474486
listener = OvertCommandListener()

test/test_transactions.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Execute Transactions Spec tests."""
1616
from __future__ import annotations
1717

18+
import asyncio
1819
import sys
1920
from io import BytesIO
2021
from test.utils_spec_runner import SpecRunner
@@ -461,6 +462,17 @@ def callback2(session):
461462
with self.client.start_session() as s:
462463
self.assertEqual(s.with_transaction(callback2), "Foo")
463464

465+
@client_context.require_transactions
466+
@client_context.require_async
467+
def test_callback_awaitable_no_coroutine(self):
468+
def callback(_):
469+
future = asyncio.Future()
470+
future.set_result("Foo")
471+
return future
472+
473+
with self.client.start_session() as s:
474+
self.assertEqual(s.with_transaction(callback), "Foo")
475+
464476
@client_context.require_transactions
465477
def test_callback_not_retried_after_timeout(self):
466478
listener = OvertCommandListener()

tools/synchro.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ def translate_coroutine_types(lines: list[str]) -> list[str]:
322322
index = lines.index(type)
323323
new = type.replace(old, res.group(3))
324324
lines[index] = new
325+
coroutine_types = [line for line in lines if "Awaitable[" in line]
326+
for type in coroutine_types:
327+
res = re.search(r"Awaitable\[([A-z]+)\]", type)
328+
if res:
329+
old = res[0]
330+
index = lines.index(type)
331+
new = type.replace(old, res.group(1))
332+
lines[index] = new
325333
return lines
326334

327335

0 commit comments

Comments
 (0)