@@ -174,7 +174,7 @@ def _gen_explain_command(
174
174
explain = SON ([('explain' , cmd )])
175
175
176
176
if session :
177
- explain ['lsid' ] = session .session_id
177
+ explain ['lsid' ] = session ._use_lsid ()
178
178
179
179
return explain
180
180
@@ -213,7 +213,7 @@ def _gen_find_command(coll, spec, projection, skip, limit, batch_size, options,
213
213
for opt , val in _OPTIONS .items ()
214
214
if options & val ])
215
215
if session :
216
- cmd ['lsid' ] = session .session_id
216
+ cmd ['lsid' ] = session ._use_lsid ()
217
217
return cmd
218
218
219
219
@@ -227,7 +227,7 @@ def _gen_get_more_command(cursor_id, coll, batch_size, max_await_time_ms,
227
227
if max_await_time_ms is not None :
228
228
cmd ['maxTimeMS' ] = max_await_time_ms
229
229
if session :
230
- cmd ['lsid' ] = session .session_id
230
+ cmd ['lsid' ] = session ._use_lsid ()
231
231
return cmd
232
232
233
233
@@ -565,10 +565,11 @@ class _BulkWriteContext(object):
565
565
"""A wrapper around SocketInfo for use with write splitting functions."""
566
566
567
567
__slots__ = ('db_name' , 'command' , 'sock_info' , 'op_id' ,
568
- 'name' , 'field' , 'publish' , 'start_time' , 'listeners' )
568
+ 'name' , 'field' , 'publish' , 'start_time' , 'listeners' ,
569
+ 'session' )
569
570
570
- def __init__ (
571
- self , database_name , command , sock_info , operation_id , listeners ):
571
+ def __init__ (self , database_name , command , sock_info , operation_id ,
572
+ listeners , session ):
572
573
self .db_name = database_name
573
574
self .command = command
574
575
self .sock_info = sock_info
@@ -578,6 +579,7 @@ def __init__(
578
579
self .name = next (iter (command ))
579
580
self .field = _FIELD_MAP [self .name ]
580
581
self .start_time = datetime .datetime .now () if self .publish else None
582
+ self .session = session
581
583
582
584
@property
583
585
def max_bson_size (self ):
@@ -628,6 +630,9 @@ def legacy_write(self, request_id, msg, max_doc_size, acknowledged, docs):
628
630
def write_command (self , request_id , msg , docs ):
629
631
"""A proxy for SocketInfo.write_command that handles event publishing.
630
632
"""
633
+ if self .session :
634
+ # Update last_use time.
635
+ self .session ._use_lsid ()
631
636
if self .publish :
632
637
duration = datetime .datetime .now () - self .start_time
633
638
self ._start (request_id , docs )
0 commit comments