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

MongoClient.is_mongos should not return an answer if not connected

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.0.3
    • Fix Version/s: 3.2
    • Component/s: None
    • Labels:
      None
    • Sprint:
      Python Sprint 26, Python Sprint 27

      Description

      Sometimes I connect a local mongos to our production environment to be able to debug something with live data. This is potentially risky if I forget this process and run our test suite later when I fixed the bug, which is why I have the following code in the module level of our test suite:

      tests/__init__.py

      c = MongoClient("mongodb://localhost:27017")
      if c.is_mongos:
          raise Exception("Connected to a local Mongos instance, need a mongod")
      

      As of upgrading to pymongo 3, this will return False before a connection is established, making this check worthless for the purpose above. For now, I've added c.server_info() before the c.is_mongos check, but I really think it should raise an exception or ensure a connection before returning an answer. Have not checked the other is_* properties as I don't use them, but maybe the problem exists there as well.

        Attachments

          Activity

            People

            Assignee:
            anna.herlihy Anna Herlihy
            Reporter:
            dbrandt Daniel Brandt
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: