Skip to content

Commit 1b3dea3

Browse files
authored
PYTHON-4533 - Convert test/test_transactions.py to async (mongodb#1732)
1 parent 875688c commit 1b3dea3

File tree

7 files changed

+1311
-25
lines changed

7 files changed

+1311
-25
lines changed

gridfs/asynchronous/grid_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ async def put(self, data: Any, **kwargs: Any) -> Any:
154154
"""
155155
async with AsyncGridIn(self._collection, **kwargs) as grid_file:
156156
await grid_file.write(data)
157-
return await grid_file._id
157+
return grid_file._id
158158

159159
async def get(self, file_id: Any, session: Optional[AsyncClientSession] = None) -> AsyncGridOut:
160160
"""Get a file from GridFS by ``"_id"``.

pymongo/asynchronous/client_session.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
Any,
145145
AsyncContextManager,
146146
Callable,
147+
Coroutine,
147148
Mapping,
148149
MutableMapping,
149150
NoReturn,
@@ -598,7 +599,7 @@ def _inherit_option(self, name: str, val: _T) -> _T:
598599

599600
async def with_transaction(
600601
self,
601-
callback: Callable[[AsyncClientSession], _T],
602+
callback: Callable[[AsyncClientSession], Coroutine[Any, Any, _T]],
602603
read_concern: Optional[ReadConcern] = None,
603604
write_concern: Optional[WriteConcern] = None,
604605
read_preference: Optional[_ServerMode] = None,
@@ -693,7 +694,7 @@ async def callback(session, custom_arg, custom_kwarg=None):
693694
read_concern, write_concern, read_preference, max_commit_time_ms
694695
)
695696
try:
696-
ret = callback(self)
697+
ret = await callback(self)
697698
except Exception as exc:
698699
if self.in_transaction:
699700
await self.abort_transaction()

0 commit comments

Comments
 (0)