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

MongoClient del raises TypeError: 'NoneType' object is not callable

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • 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 del can raise TypeError: 'NoneType' object is not callable at interpreter shutdown:

      $ python
      Python 3.13.0 (v3.13.0:60403a5409f, Oct  7 2024, 00:37:40) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> client = MongoClient()
      >>> exit()
      Exception ignored in: <function MongoClient.__del__ at 0x127bf02c0>
      Traceback (most recent call last):
        File "/Users/shane/git/mongo-python-driver/pymongo/synchronous/mongo_client.py", line 1192, in __del__
      TypeError: 'NoneType' object is not callable
      

      At interpreter shutdown global variables can be set to None so we have to guard against this case:

                  warn = warning.warn
                  cls = ResourceWarning
                  if self._opened and not self._closed and warn and cls:
                      warn(
                          (
                              f"Unclosed {type(self).__name__} opened at:\n{self._topology_settings._stack}"
                              f"Call {self.__class__.__name__}.close() to safely shut down your client and free up resources."
                          ),
                          cls,
                          stacklevel=2,
                      )
      

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

              Created:
              Updated: