diff --git a/doc/contributors.rst b/doc/contributors.rst index c99c4b80e..22cbee321 100644 --- a/doc/contributors.rst +++ b/doc/contributors.rst @@ -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) \ No newline at end of file +- Henri Froese (henrifroese) +- Ishmum Jawad Khan (ishmum123) diff --git a/pymongo/client_session.py b/pymongo/client_session.py index 7d9ce712f..f8071e5f2 100644 --- a/pymongo/client_session.py +++ b/pymongo/client_session.py @@ -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): diff --git a/test/test_session.py b/test/test_session.py index fc1f8382f..608024e0b 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -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):