Skip to content

Commit 55aaee3

Browse files
committed
Fix typing
1 parent af572bd commit 55aaee3

File tree

6 files changed

+10
-6
lines changed

6 files changed

+10
-6
lines changed

pymongo/asynchronous/change_stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ async def _run_aggregation_cmd(
258258

259259
async def _create_cursor(self) -> AsyncCommandCursor: # type: ignore[type-arg]
260260
async with self._client._tmp_session(self._session) as s:
261-
s.leave_alive = True
261+
if s:
262+
s.leave_alive = True
262263
return await self._run_aggregation_cmd(session=s)
263264

264265
async def _resume(self) -> None:

pymongo/asynchronous/command_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def session(self) -> Optional[AsyncClientSession]:
197197
198198
.. versionadded:: 3.6
199199
"""
200-
if not self._session.implicit:
200+
if self._session and not self._session.implicit:
201201
return self._session
202202
return None
203203

pymongo/asynchronous/database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ async def create_collection(
611611
common.validate_is_mapping("clusteredIndex", clustered_index)
612612

613613
async with self._client._tmp_session(session) as s:
614-
s.leave_alive = True
614+
if s:
615+
s.leave_alive = True
615616
# Skip this check in a transaction where listCollections is not
616617
# supported.
617618
if (

pymongo/synchronous/change_stream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ def _run_aggregation_cmd(self, session: Optional[ClientSession]) -> CommandCurso
256256

257257
def _create_cursor(self) -> CommandCursor: # type: ignore[type-arg]
258258
with self._client._tmp_session(self._session) as s:
259-
s.leave_alive = True
259+
if s:
260+
s.leave_alive = True
260261
return self._run_aggregation_cmd(session=s)
261262

262263
def _resume(self) -> None:

pymongo/synchronous/command_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def session(self) -> Optional[ClientSession]:
197197
198198
.. versionadded:: 3.6
199199
"""
200-
if not self._session.implicit:
200+
if self._session and not self._session.implicit:
201201
return self._session
202202
return None
203203

pymongo/synchronous/database.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,8 @@ def create_collection(
611611
common.validate_is_mapping("clusteredIndex", clustered_index)
612612

613613
with self._client._tmp_session(session) as s:
614-
s.leave_alive = True
614+
if s:
615+
s.leave_alive = True
615616
# Skip this check in a transaction where listCollections is not
616617
# supported.
617618
if (

0 commit comments

Comments
 (0)