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

Improve how we raise DeprecationWarnings in Motor

    • Type: Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      For the most part, Motor relies on the calls to the underlying PyMongo functions to raise DeprecationWarnings. Since these synchronous calls are run using a thread pool executor, the application must be run using -Wdefault in order to make the warning user-visible. For example:

      $ # test script
      $ cat sample.py 
      import asyncio
      from motor.motor_asyncio import AsyncIOMotorClient
      
      async def main():
          client = AsyncIOMotorClient()
          print(await client.admin.command('ping'))
          print(client.nodes)
          await client.fsync()
      
      asyncio.run(main())
      $
      $ #  running without -W
      $ python sample.py
      {'ok': 1.0}
      frozenset({('localhost', 27017)})
      $ 
      $ # running it with -W
      $ python -Wdefault sample.py
      {'ok': 1.0}
      frozenset({('localhost', 27017)})
      /Users/pmital/.pyenv/versions/3.7.5/lib/python3.7/concurrent/futures/thread.py:57: DeprecationWarning: fsync is deprecated. Use client.admin.command('fsync') instead.
        result = self.fn(*self.args, **self.kwargs)
      
      

      We should come up with a better way to raise these warnings so that applications don't need to change their invocation to see them.

            Assignee:
            william.zhou@mongodb.com William Zhou
            Reporter:
            prashant.mital Prashant Mital (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: