Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
aclark4life wants to merge13 commits intomongodb:masterfromaclark4life:PYTHON-4542

Conversation

aclark4life
Copy link
Contributor

  • 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
Copy link
Member

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 inClientSession.__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)withsession1:session2=client.start_session(bind=True)withsession2:coll.find_one()# uses session2coll.find_one()# uses session1coll.find_one()# uses implicit session

aclark4life reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done in3c68a70

with session2:
coll.find_one() # uses session2
coll.find_one() # uses session1
coll.find_one() # uses implicit session
Copy link
Member

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.

Copy link
ContributorAuthor

@aclark4lifeaclark4lifeJun 2, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

How about comparing with the cursor session ? E.g.c36e9df

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@ShaneHarvey I'm assuming that commit is wrong, I should be using command monitoring via event listeners right?

bind = opts._bind
session = client_session.AsyncClientSession(self, server_session, opts, implicit)
if bind:
_SESSION.set(session)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This needs to be removed. We should only bind in__enter__.

aclark4life reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done in3c68a70

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

@ShaneHarvey OK to resolve this one?

@@ -545,9 +548,12 @@ def _check_ended(self) -> None:
raise InvalidOperation("Cannot use ended session")

async def __aenter__(self) -> AsyncClientSession:
self._token = _SESSION.set(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should only do this if the bind option is set to True.

aclark4life reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done in71eca08

@aclark4lifeaclark4life marked this pull request as ready for reviewMay 23, 2025 18:33
@aclark4lifeaclark4life closed this by deleting the head repositoryJun 10, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ShaneHarveyShaneHarveyAwaiting requested review from ShaneHarvey

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@aclark4life@ShaneHarvey

[8]ページ先頭

©2009-2025 Movatter.jp