Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1915

Prohibit copying ClientSession objects

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
    • Minor Change

      It should not be possible to copy a ClientSession. A ClientSession maintains transaction state which cannot be duplicated. Also when a ClientSession is copied, the underlying server session is also duplicated, eventually resulting in duplicate _ServerSession objects in the pool:

      >>> import copy
      >>> s = client.start_session()
      >>> s._server_session
      <pymongo.client_session._ServerSession object at 0x10408b438>
      >>> s2 = copy.copy(s)
      >>> s._server_session
      <pymongo.client_session._ServerSession object at 0x10408b438>
      >>> s2._server_session
      <pymongo.client_session._ServerSession object at 0x10408b438>
      >>> client._topology._session_pool
      deque([])
      >>> s.end_session()
      >>> s2.end_session()
      >>> client._topology._session_pool
      deque([<pymongo.client_session._ServerSession object at 0x10408b438>, <pymongo.client_session._ServerSession object at 0x10408b438>])
      

            Assignee:
            julius.park@mongodb.com Julius Park (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: