PYTHON-1915 Prohibit copying ClientSession objects (#726)

This commit is contained in:
Julius Park 2021-09-15 12:05:09 -07:00 committed by GitHub
parent 0fa86c8ee1
commit 4e086ba218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 1 deletions

View File

@ -89,4 +89,5 @@ The following is a list of people who have contributed to
- Paul Fisher (thetorpedodog)
- Julius Park (juliusgeo)
- Khanh Nguyen (KN99HN)
- Henri Froese (henrifroese)
- Henri Froese (henrifroese)
- Ishmum Jawad Khan (ishmum123)

View File

@ -953,6 +953,9 @@ class ClientSession(object):
if self._snapshot_time is not None:
rc['atClusterTime'] = self._snapshot_time
def __copy__(self):
raise TypeError('A ClientSession cannot be copied, create a new session instead')
class _ServerSession(object):
def __init__(self, generation):

View File

@ -716,6 +716,10 @@ class TestSession(IntegrationTest):
snapshot=True):
pass
def test_session_not_copyable(self):
client = self.client
with client.start_session() as s:
self.assertRaises(TypeError, lambda: copy.copy(s))
class TestCausalConsistency(unittest.TestCase):