-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-4542 Improved sessions API #2335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
aclark4life
commented
May 7, 2025
- Via context variable.
- Via context variable.
@@ -222,6 +224,7 @@ def __init__( | |||
) | |||
self._default_transaction_options = default_transaction_options | |||
self._snapshot = snapshot | |||
self._bind = bind |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to bind/unbind the session in ClientSession.__enter__/__exit__
. That way the stack of sessions is managed correctly (ie we call _SESSION.reset(token)
). Think about how nested cases will work:
session1 = client.start_session(bind=True)
with session1:
session2 = client.start_session(bind=True)
with session2:
coll.find_one() # uses session2
coll.find_one() # uses session1
coll.find_one() # uses implicit session
test/asynchronous/test_session.py
Outdated
with session2: | ||
coll.find_one() # uses session2 | ||
coll.find_one() # uses session1 | ||
coll.find_one() # uses implicit session |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test has to actually verify the correct sessions are used via command monitoring events.