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

KeyError parsing error response from mongos

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.8, 3.0
    • Affects Version/s: 2.7.2
    • Component/s: None
    • None
    • Fully Compatible

      Start a sharded cluster of two-member replica sets and kill a primary, so one of the shards has only a secondary.

      >>> c = pymongo.MongoClient()
      >>> c.test.command('dbstats')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/Users/emptysquare/.virtualenvs/motor/lib/python2.7/site-packages/pymongo/database.py", line 437, in command
          uuid_subtype, compile_re, **kwargs)[0]
        File "/Users/emptysquare/.virtualenvs/motor/lib/python2.7/site-packages/pymongo/database.py", line 343, in _command
          msg, allowable_errors)
        File "/Users/emptysquare/.virtualenvs/motor/lib/python2.7/site-packages/pymongo/helpers.py", line 151, in _check_command_response
          errmsg = details["errmsg"]
      KeyError: 'errmsg'
      >>> c.server_info()['version']
      u'2.4.9'
      >>> c.server_info()['gitVersion']
      u'52fe0d21959e32a5bdbecdc62057db386e4e029c'
      

      The problem is mongos's error structure:

      {
      	"raw" : {
      		"shard0/localhost:4000,localhost:4001" : {
      
      		}
      	},
      	"ok" : 0,
      	"errmsg" : "{ shard0/localhost:4000,localhost:4001: \"result without error message returned : {}\" }"
      }
      

      PyMongo expects the "raw" error from shard0 to be a full error document, but it's empty. I've tested this with 2.4.9 and 2.6.4.

      PyMongo on the current 3.0-dev raises KeyError for the same reason.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: