Skip to content

Commit 981e392

Browse files
committed
PYTHON-1529 - No implicit sessions with parallel_scan
1 parent 54b8058 commit 981e392

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pymongo/collection.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,16 +1493,24 @@ def parallel_scan(self, num_cursors, session=None, **kwargs):
14931493
cmd.update(kwargs)
14941494

14951495
with self._socket_for_reads(session) as (sock_info, slave_ok):
1496-
result = self._command(sock_info, cmd, slave_ok,
1497-
read_concern=self.read_concern,
1498-
session=session)
1496+
# We call sock_info.command here directly, instead of
1497+
# calling self._command to avoid using an implicit session.
1498+
result = sock_info.command(
1499+
self.__database.name,
1500+
cmd,
1501+
slave_ok,
1502+
self._read_preference_for(session),
1503+
self.codec_options,
1504+
read_concern=self.read_concern,
1505+
parse_write_concern_error=True,
1506+
session=session,
1507+
client=self.__database.client)
14991508

15001509
cursors = []
15011510
for cursor in result['cursors']:
1502-
s = self.__database.client._ensure_session(session)
15031511
cursors.append(CommandCursor(
15041512
self, cursor['cursor'], sock_info.address,
1505-
session=s, explicit_session=session is not None))
1513+
session=session, explicit_session=session is not None))
15061514

15071515
return cursors
15081516

test/test_session.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,9 @@ def scan(session=None):
332332
c.batch_size(2)
333333
list(c)
334334

335-
self._test_ops(client, (scan, [], {}))
336-
337-
# Implicit session with parallel_scan is uncorrelated with cursors',
338-
# but each cursor's getMores all use the same lsid.
339335
listener.results.clear()
340-
scan()
336+
with client.start_session() as session:
337+
scan(session)
341338
cursor_lsids = {}
342339
for event in listener.results['started']:
343340
self.assertIn(

0 commit comments

Comments
 (0)