Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-979

Attempting to use AsyncIOMotorClient without a running loop should raise DeprecationWarning

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.1
    • Affects Version/s: None
    • Component/s: None
    • None

      The solution implemented in MOTOR-902 uses:

              return asyncio.get_event_loop_policy().get_event_loop()
      

      to attempt to workaround https://bugs.python.org/issue39529

      This was pointed out to us as problematic by a (the?) Tornado maintainer here: https://github.com/mongodb/motor/pull/170

      The gist is that even though asyncio.get_event_loop_policy().get_event_loop() is not deprecated in Python yet, it will break when the asyncio.get_event_loop() behavior is changed (planned for Python 3.12). We want users to see DeprecationWarnings when using motor incorrectly like this:

      >>> import motor.motor_asyncio
      >>> client = motor.motor_asyncio.AsyncIOMotorClient()
      >>> client.test.pages.drop()  # this should raise a DeprecationWarning because it was called without a running loop
      

            Assignee:
            steve.silvester@mongodb.com Steve Silvester
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: