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

Stop using MongoClient.address for hashing and equality

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.0
    • Affects Version/s: None
    • Component/s: None
    • None

      MongoClient.address and how it's used internally by MongoClient has a number of problems. First, client.address does not always block for the primary to be discovered. For example:

      >>> client = MongoClient(connect=False)
      >>> client.topology_description
      <TopologyDescription id: 617af87d67f12b13103312e5, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None>]>
      >>> client.address
      >>> client.topology_description
      <TopologyDescription id: 617af87d67f12b13103312e5, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None>]>
      >>> client.admin.command('hello')['me']
      'localhost:27017'
      >>> client.topology_description
      <TopologyDescription id: 617af87d67f12b13103312e5, topology_type: ReplicaSetWithPrimary, servers: [<ServerDescription ('localhost', 27017) server_type: RSPrimary, rtt: 0.0008715150179341435>]>
      >>> client.address
      ('localhost', 27017)
      

      Second, client.address is used for comparison and hashing in client._eq_ and client._hash_ which does not make sense since 1) client.address can block and 2) client.address can change.

      We should change client._eq_ and client._hash_ to use something immutable like the connection string or list of seeds.

            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: