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

MongoClient.event_listeners does not work as documented

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 4.0
    • Affects Version/s: 3.3
    • Component/s: None
    • None

      MongoClient.event_listeners does not work as documented:

          @property
          def event_listeners(self):
              """The event listeners registered for this client.
      
              See :mod:`~pymongo.monitoring` for details.
              """
              return self._event_listeners.event_listeners
      

      One would expect for event_listeners to return the list of event listeners passed to MongoClient. However, this is what it actually does:

      >>> from pymongo import event_loggers
      >>> listeners = [event_loggers.CommandLogger(),
      ...              event_loggers.HeartbeatLogger(),
      ...              event_loggers.ServerLogger(),
      ...              event_loggers.TopologyLogger(),
      ...              event_loggers.ConnectionPoolLogger()]
      >>> c = MongoClient(event_listeners=listeners)
      WARNING:root:No writable servers available.
      WARNING:root:No readable servers available.
      >>> c.event_listeners
      <bound method _EventListeners.event_listeners of <pymongo.monitoring._EventListeners object at 0x7fea50a8d2e0>>
      >>> c.event_listeners()
      ([<pymongo.event_loggers.CommandLogger object at 0x7fea4d090d90>], [<pymongo.event_loggers.HeartbeatLogger object at 0x7fea50a74ca0>], [<pymongo.event_loggers.ServerLogger object at 0x7fea50a74c40>], [<pymongo.event_loggers.TopologyLogger object at 0x7fea50a74c10>])
      

      So there are multiple issues:

      • it's not actually a property
      • it doesn't return a list
      • it doesn't return the Connection Pool listener

      The expected behavior should be a property that returns all the listeners in one list:

      ...
      >>> c.event_listeners
      [<pymongo.event_loggers.CommandLogger object at 0x7feeab090d90>, <pymongo.event_loggers.HeartbeatLogger object at 0x7feeaea40c10>, <pymongo.event_loggers.ServerLogger object at 0x7feeaea40cd0>, <pymongo.event_loggers.TopologyLogger object at 0x7feeaea40ee0>, <pymongo.event_loggers.ConnectionPoolLogger object at 0x7feeaea40e80>]
      

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

              Created:
              Updated:
              Resolved: