Skip to content

Commit d65fe45

Browse files
committed
WIP
1 parent daf5f84 commit d65fe45

File tree

7 files changed

+8
-4
lines changed

7 files changed

+8
-4
lines changed

pymongo/asynchronous/client_session.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137

138138
import collections
139139
import time
140-
import traceback
141140
import uuid
142141
from collections.abc import Mapping as _Mapping
143142
from typing import (

pymongo/asynchronous/mongo_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import asyncio
3636
import contextlib
3737
import os
38-
import traceback
3938
import warnings
4039
import weakref
4140
from collections import defaultdict

pymongo/synchronous/change_stream.py

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

257257
def _create_cursor(self) -> CommandCursor: # type: ignore[type-arg]
258-
with self._client._tmp_session(self._session, close=False) as s:
258+
with self._client._tmp_session(self._session) as s:
259259
return self._run_aggregation_cmd(session=s)
260260

261261
def _resume(self) -> None:

pymongo/synchronous/client_session.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,14 @@ def _end_session(self, lock: bool) -> None:
536536
def _end_implicit_session(self) -> None:
537537
# Implicit sessions can't be part of transactions or pinned connections
538538
if self._server_session is not None:
539+
# print(f"Ending session {self}, implicit: {self._implicit}, attached: {self._attached_to_cursor}")
539540
self._client._return_server_session(self._server_session)
540541
self._server_session = None
541542

542543
def _check_ended(self) -> None:
543544
if self._server_session is None:
545+
# print(f"Session {self} is already ended")
546+
# print(f"Session {self} is already ended, implicit: {self._implicit}, attached: {self._attached_to_cursor}: {''.join(traceback.format_stack())}")
544547
raise InvalidOperation("Cannot use ended session")
545548

546549
def __enter__(self) -> ClientSession:

pymongo/synchronous/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2577,7 +2577,7 @@ def _cmd(
25772577
cmd_cursor._maybe_pin_connection(conn)
25782578
return cmd_cursor
25792579

2580-
with self._database.client._tmp_session(session, False) as s:
2580+
with self._database.client._tmp_session(session) as s:
25812581
return self._database.client._retryable_read(
25822582
_cmd, read_pref, s, operation=_Op.LIST_INDEXES
25832583
)

pymongo/synchronous/command_cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ def _die_lock(self) -> None:
242242
def _end_session(self) -> None:
243243
if self._session:
244244
if self._session.implicit:
245+
# print(f"Ending session {self}, session: {self._session}")
245246
self._session._end_implicit_session()
246247
self._session = None
247248

pymongo/synchronous/mongo_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ def _retryable_write(
20802080
:param bulk: bulk abstraction to execute operations in bulk, defaults to None
20812081
"""
20822082
with self._tmp_session(session) as s:
2083+
# print(f"Called retryable write with session = {session!r} and got {s}: {s._server_session!r}")
20832084
return self._retry_with_session(retryable, func, s, bulk, operation, operation_id)
20842085

20852086
def _cleanup_cursor_no_lock(
@@ -2286,6 +2287,7 @@ def _tmp_session(
22862287
finally:
22872288
# Call end_session when we exit this scope.
22882289
if not s.attached_to_cursor:
2290+
# print(f"Ending session {s}: {''.join(traceback.format_stack(limit=10))}")
22892291
s.end_session()
22902292
else:
22912293
yield None

0 commit comments

Comments
 (0)