Skip to content

Commit 55e833f

Browse files
committed
Fix token
1 parent 71eca08 commit 55e833f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

pymongo/asynchronous/client_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ def __init__(
517517
# Is this an implicitly created session?
518518
self._implicit = implicit
519519
self._transaction = _Transaction(None, client)
520+
self._token = None
520521

521522
async def end_session(self) -> None:
522523
"""Finish this session. If a transaction has started, abort it.
@@ -555,6 +556,7 @@ async def __aenter__(self) -> AsyncClientSession:
555556
async def __aexit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
556557
if self._token:
557558
_SESSION.reset(self._token)
559+
self._token = None
558560
await self._end_session(lock=True)
559561

560562
@property

pymongo/synchronous/client_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ def __init__(
516516
# Is this an implicitly created session?
517517
self._implicit = implicit
518518
self._transaction = _Transaction(None, client)
519+
self._token = None
519520

520521
def end_session(self) -> None:
521522
"""Finish this session. If a transaction has started, abort it.
@@ -554,6 +555,7 @@ def __enter__(self) -> ClientSession:
554555
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None:
555556
if self._token:
556557
_SESSION.reset(self._token)
558+
self._token = None
557559
self._end_session(lock=True)
558560

559561
@property

0 commit comments

Comments
 (0)