Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-4758

MongoClient with connect=False still generates a resource warning

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.9
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      MongoClient with connect=False still generates a resource warning:

          def test_client_options(self):
              c = MongoClient(connect=False)
              self.assertIsInstance(c.options, ClientOptions)
              self.assertIsInstance(c.options.pool_options, PoolOptions)
              self.assertEqual(c.options.server_selection_timeout, 30)
              self.assertEqual(c.options.pool_options.max_idle_time_seconds, None)
              self.assertIsInstance(c.options.retry_writes, bool)
              self.assertIsInstance(c.options.retry_reads, bool)
      

      Generates this warning:

      test_client_options (__main__.ClientUnitTest.test_client_options) ... /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py:589: ResourceWarning: Unclosed MongoClient opened at:
        File "/Users/shane/git/mongo-python-driver/test/test_client.py", line 2459, in <module>
          unittest.main()
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/main.py", line 105, in __init__
          self.runTests()
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/main.py", line 281, in runTests
          self.result = testRunner.run(self.test)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/runner.py", line 240, in run
          test(result)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 84, in __call__
          return self.run(*args, **kwds)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 122, in run
          test(result)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 84, in __call__
          return self.run(*args, **kwds)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/suite.py", line 122, in run
          test(result)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 690, in __call__
          return self.run(*args, **kwds)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 634, in run
          self._callTestMethod(testMethod)
        File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/unittest/case.py", line 589, in _callTestMethod
          if method() is not None:
        File "/Users/shane/git/mongo-python-driver/test/test_client.py", line 579, in test_client_options
          c = MongoClient(connect=False)
      Call MongoClient.close() to safely shut down your client and free up resources.
        if method() is not None:
      ResourceWarning: Enable tracemalloc to get the object allocation traceback
      

            Assignee:
            noah.stapp@mongodb.com Noah Stapp
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: