Skip to content

Commit f241650

Browse files
committed
Fix test
1 parent 969abb2 commit f241650

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

pymongo/asynchronous/mongo_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,15 +2268,14 @@ async def _tmp_session(
22682268
self, session: Optional[client_session.AsyncClientSession]
22692269
) -> AsyncGenerator[Optional[client_session.AsyncClientSession], None]:
22702270
"""If provided session is None, lend a temporary session."""
2271+
if session is not None and not isinstance(session, client_session.AsyncClientSession):
2272+
raise ValueError(
2273+
f"'session' argument must be an AsyncClientSession or None, not {type(session)}"
2274+
)
22712275

22722276
# Check for a bound session. If one exists, treat it as an explicitly passed session.
22732277
session = session or self._get_bound_session()
2274-
2275-
if session is not None:
2276-
if not isinstance(session, client_session.AsyncClientSession):
2277-
raise ValueError(
2278-
f"'session' argument must be an AsyncClientSession or None, not {type(session)}"
2279-
)
2278+
if session:
22802279
# Don't call end_session.
22812280
yield session
22822281
return

pymongo/synchronous/mongo_client.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,15 +2264,14 @@ def _tmp_session(
22642264
self, session: Optional[client_session.ClientSession]
22652265
) -> Generator[Optional[client_session.ClientSession], None]:
22662266
"""If provided session is None, lend a temporary session."""
2267+
if session is not None and not isinstance(session, client_session.ClientSession):
2268+
raise ValueError(
2269+
f"'session' argument must be a ClientSession or None, not {type(session)}"
2270+
)
22672271

22682272
# Check for a bound session. If one exists, treat it as an explicitly passed session.
22692273
session = session or self._get_bound_session()
2270-
2271-
if session is not None:
2272-
if not isinstance(session, client_session.ClientSession):
2273-
raise ValueError(
2274-
f"'session' argument must be a ClientSession or None, not {type(session)}"
2275-
)
2274+
if session:
22762275
# Don't call end_session.
22772276
yield session
22782277
return

test/asynchronous/test_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ async def test_nested_session_binding(self):
877877

878878
session1 = self.client.start_session()
879879
session2 = self.client.start_session()
880+
session1._materialize()
881+
session2._materialize()
880882
try:
881883
self.listener.reset()
882884
# Uses implicit session

test/test_session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,8 @@ def test_nested_session_binding(self):
877877

878878
session1 = self.client.start_session()
879879
session2 = self.client.start_session()
880+
session1._materialize()
881+
session2._materialize()
880882
try:
881883
self.listener.reset()
882884
# Uses implicit session

0 commit comments

Comments
 (0)