diff --git a/doc/contributors.rst b/doc/contributors.rst index 4118d55586..74164ffd59 100644 --- a/doc/contributors.rst +++ b/doc/contributors.rst @@ -88,3 +88,4 @@ The following is a list of people who have contributed to - Terence Honles (terencehonles) - Paul Fisher (thetorpedodog) - Julius Park (juliusgeo) +- Ishmum Jawad Khan (ishmum123) diff --git a/pymongo/client_session.py b/pymongo/client_session.py index dec2f4f918..e2d7caca58 100644 --- a/pymongo/client_session.py +++ b/pymongo/client_session.py @@ -827,6 +827,9 @@ def _start_retryable_write(self): self._check_ended() self._server_session.inc_transaction_id() + 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 50dfd8a060..e1db9ccfd1 100644 --- a/test/test_session.py +++ b/test/test_session.py @@ -779,6 +779,11 @@ def drop_db(): wait_until(drop_db, 'dropped database after w=0 writes') + 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):