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

Unhandled KeyError exception in __find_primary function of MongoReplicaSetClient class

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.1
    • Affects Version/s: 2.4.1
    • Component/s: None
    • None
    • Environment:
      Ubuntu 12.04 64-bit
      Python 2.7.3

      During a resiliency test script for our mongodb replica set, the primary member was shut down as read queries were sent to the replica set through the MongoReplicaSetClient class by the find_one() function.

      The following call was made that caused the error:

         exclude = {'_id' : False}
      
          for _ in xrange(total_queries):
              query = {'number' : random.randint(0, MAX_COLLECTION_SIZE)}
              
              try:
                  results = collection.find_one(query,
                                                fields=exclude)
      

      here's the backtrace:

      File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py", line 598, in find_one
          for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
        File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 814, in next
          if len(self.__data) or self._refresh():
        File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 763, in _refresh
          self.__uuid_subtype))
        File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line 700, in __send_message
          **kwargs)
        File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_replica_set_client.py", line 1120, in _send_message_with_response
          self.__find_primary()
        File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_replica_set_client.py", line 858, in __find_primary
          primary = self.__members[self.__writer]
      KeyError: (u'10.12.30.86', 27017)
      

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            drodriguez Diego Rodriguez
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: