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

test_init_disconnected_with_srv cannot run against sharded Topologies

    • Type: Icon: Build Failure Build Failure
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 4.12.1
    • Affects Version/s: None
    • Component/s: None
    • 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?
    • None
    • None
    • None
    • None
    • None
    • None

      Name of Failure:

      test.test_client.TestClient.test_init_disconnected_with_srv

      Link to task:

      https://spruce.mongodb.com/task/mongo_python_driver_other_hosts_rhel8_zseries_latest_test_sync_auth_ssl_sharded_cluster_patch_e2e673edeb711e24d7feb620e7552a2a7af2f0b0_680913f2c7ee9c000741f853_25_04_23_16_23_25?execution=0&sortBy=STATUS&sortDir=ASC

      Context of when and why the failure occurred:

      Intended behavior of MongoClient.address.

      Stack trace:

       [2025/04/23 10:10:12.482] FAILURE: pymongo.errors.InvalidOperation: Cannot use "address" property when load balancing among mongoses, use "nodes" instead. ()
       [2025/04/23 10:10:12.482] self = <test.test_client.TestClient testMethod=test_init_disconnected_with_srv>
       [2025/04/23 10:10:12.482]     @client_context.require_no_standalone
       [2025/04/23 10:10:12.482]     @client_context.require_no_load_balancer
       [2025/04/23 10:10:12.482]     @client_context.require_tls
       [2025/04/23 10:10:12.482]     def test_init_disconnected_with_srv(self):
       [2025/04/23 10:10:12.482]         c = self.rs_or_single_client(
       [2025/04/23 10:10:12.482]             "mongodb+srv://test1.test.build.10gen.cc", connect=False, tlsInsecure=True
       [2025/04/23 10:10:12.482]         )
       [2025/04/23 10:10:12.482]         # nodes returns an empty set if not connected
       [2025/04/23 10:10:12.482]         self.assertEqual(c.nodes, frozenset())
       [2025/04/23 10:10:12.482]         # topology_description returns the initial seed description if not connected
       [2025/04/23 10:10:12.482]         topology_description = c.topology_description
       [2025/04/23 10:10:12.482]         self.assertEqual(topology_description.topology_type, TOPOLOGY_TYPE.Unknown)
       [2025/04/23 10:10:12.482]         self.assertEqual(
       [2025/04/23 10:10:12.482]             {
       [2025/04/23 10:10:12.482]                 ("test1.test.build.10gen.cc", None): ServerDescription(
       [2025/04/23 10:10:12.482]                     ("test1.test.build.10gen.cc", None)
       [2025/04/23 10:10:12.482]                 )
       [2025/04/23 10:10:12.482]             },
       [2025/04/23 10:10:12.482]             topology_description.server_descriptions(),
       [2025/04/23 10:10:12.482]         )
       [2025/04/23 10:10:12.482]     
       [2025/04/23 10:10:12.482]         # address causes client to block until connected
       [2025/04/23 10:10:12.482] >       self.assertIsNotNone(c.address)
       [2025/04/23 10:10:12.482] test/test_client.py:850: 
       [2025/04/23 10:10:12.482] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
       [2025/04/23 10:10:12.482] self = MongoClient(host=['localhost.test.build.10gen.cc:27017', 'localhost.test.build.10gen.cc:27018'], document_class=dict, ...', tlsinsecure=True, tlsallowinvalidhostnames=True, tlsdisableocspendpointcheck=True, tlsallowinvalidcertificates=True)
       [2025/04/23 10:10:12.482]     @property
       [2025/04/23 10:10:12.482]     def address(self) -> Optional[tuple[str, int]]:
       [2025/04/23 10:10:12.482]         """(host, port) of the current standalone, primary, or mongos, or None.
       [2025/04/23 10:10:12.482]     
       [2025/04/23 10:10:12.482]         Accessing :attr:`address` raises :exc:`~.errors.InvalidOperation` if
       [2025/04/23 10:10:12.482]         the client is load-balancing among mongoses, since there is no single
       [2025/04/23 10:10:12.482]         address. Use :attr:`nodes` instead.
       [2025/04/23 10:10:12.482]     
       [2025/04/23 10:10:12.482]         If the client is not connected, this will block until a connection is
       [2025/04/23 10:10:12.482]         established or raise ServerSelectionTimeoutError if no server is
       [2025/04/23 10:10:12.482]         available.
       [2025/04/23 10:10:12.482]     
       [2025/04/23 10:10:12.482]         .. versionadded:: 3.0
       [2025/04/23 10:10:12.482]         """
       [2025/04/23 10:10:12.482]         if self._topology is None:
       [2025/04/23 10:10:12.482]             self._get_topology()
       [2025/04/23 10:10:12.482]         topology_type = self._topology._description.topology_type
       [2025/04/23 10:10:12.482]         if (
       [2025/04/23 10:10:12.482]             topology_type == TOPOLOGY_TYPE.Sharded
       [2025/04/23 10:10:12.482]             and len(self.topology_description.server_descriptions()) > 1
       [2025/04/23 10:10:12.482]         ):
       [2025/04/23 10:10:12.482] >           raise InvalidOperation(
       [2025/04/23 10:10:12.482]                 'Cannot use "address" property when load balancing among'
       [2025/04/23 10:10:12.482]                 ' mongoses, use "nodes" instead.'
       [2025/04/23 10:10:12.482]             )
       [2025/04/23 10:10:12.482] E           pymongo.errors.InvalidOperation: Cannot use "address" property when load balancing among mongoses, use "nodes" instead.
       [2025/04/23 10:10:12.482] pymongo/synchronous/mongo_client.py:1593: InvalidOperation
      

            Assignee:
            noah.stapp@mongodb.com Noah Stapp
            Reporter:
            noah.stapp@mongodb.com Noah Stapp
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: