Skip to content

Commit 3c68a70

Browse files
committed
Only bind in __enter__
1 parent 0f9e93a commit 3c68a70

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

pymongo/asynchronous/mongo_client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
from pymongo.asynchronous import client_session, database, uri_parser
6666
from pymongo.asynchronous.change_stream import AsyncChangeStream, AsyncClusterChangeStream
6767
from pymongo.asynchronous.client_bulk import _AsyncClientBulk
68-
from pymongo.asynchronous.client_session import _SESSION, _EmptyServerSession
68+
from pymongo.asynchronous.client_session import _EmptyServerSession
6969
from pymongo.asynchronous.command_cursor import AsyncCommandCursor
7070
from pymongo.asynchronous.settings import TopologySettings
7171
from pymongo.asynchronous.topology import Topology, _ErrorContext
@@ -1355,11 +1355,7 @@ def _close_cursor_soon(
13551355
def _start_session(self, implicit: bool, **kwargs: Any) -> AsyncClientSession:
13561356
server_session = _EmptyServerSession()
13571357
opts = client_session.SessionOptions(**kwargs)
1358-
bind = opts._bind
1359-
session = client_session.AsyncClientSession(self, server_session, opts, implicit)
1360-
if bind:
1361-
_SESSION.set(session)
1362-
return session
1358+
return client_session.AsyncClientSession(self, server_session, opts, implicit)
13631359

13641360
def start_session(
13651361
self,

pymongo/synchronous/mongo_client.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
from pymongo.synchronous import client_session, database, uri_parser
108108
from pymongo.synchronous.change_stream import ChangeStream, ClusterChangeStream
109109
from pymongo.synchronous.client_bulk import _ClientBulk
110-
from pymongo.synchronous.client_session import _SESSION, _EmptyServerSession
110+
from pymongo.synchronous.client_session import _EmptyServerSession
111111
from pymongo.synchronous.command_cursor import CommandCursor
112112
from pymongo.synchronous.settings import TopologySettings
113113
from pymongo.synchronous.topology import Topology, _ErrorContext
@@ -1353,11 +1353,7 @@ def _close_cursor_soon(
13531353
def _start_session(self, implicit: bool, **kwargs: Any) -> ClientSession:
13541354
server_session = _EmptyServerSession()
13551355
opts = client_session.SessionOptions(**kwargs)
1356-
bind = opts._bind
1357-
session = client_session.ClientSession(self, server_session, opts, implicit)
1358-
if bind:
1359-
_SESSION.set(session)
1360-
return session
1356+
return client_session.ClientSession(self, server_session, opts, implicit)
13611357

13621358
def start_session(
13631359
self,

0 commit comments

Comments
 (0)