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
MOTOR-979 Use asyncio.get_event_loop so that DeprecationWarnings are correctly issued #170
Conversation
I think there's a misunderstanding here. We don't want this line to raise a DeprecationWarning or fail with an error because a loop wasn't created. We intentionally decided that we what this code to continue working like it does in Python <3.9 where motor will implicitly create and start a loop on the current thread. With that in mind, we can't merge this PR. Is there an alternative way you'd suggest accomplishing our goal? |
This will only raise a DeprecationWarning if the caller has opted into this behavior |
We don't want this line to raise a DeprecationWarning even if the user opts into warnings. |
I think @graingert's point is that we're masking an issue that will cause breakage in Python 3.12 (assuming they stick to their schedule of aliasing |
In this case I think that CPython is incorrectly not raising DeprecationWarning from Perhaps we should revisit this and just follow asyncio's lead. We'd need to re-evaluate the problem as a whole though. For example, if we create a client before there's a loop (or a running loop) should we auto create a new loop? Or should we pin to the current loop when the client is first used? |
This works correctly already, as AsyncIOMotorClient now mostly follows the asyncio.mixins._LoopBoundMixin pattern:
|
Okay I believe I'm on the same page now. I opened https://jira.mongodb.org/browse/MOTOR-979 to track. |
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.
LGTM!
I opened https://jira.mongodb.org/browse/MOTOR-980 to track the docs failure. Thanks @graingert! |
…issued
It looks like a workaround I wrote in Tornado was incorrectly incorporated into AsyncioMotorClient here https://github.com/mongodb/motor/pull/155/files#r851429040
if a user has opted into DeprecationWarnings as errors
asyncio.get_event_loop_policy().get_event_loop()
incorrectly suppresses the deprecation warning: