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

Safe write acknowledgement (getLastError) fails on MongoDB 2.1.x when authentication is enabled.

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

      In MongoDB 2.1.x and newer (dev versions of what will be MongoDB 2.2) getLastError requires authentication. That means you have to be authenticated to the db the getLastError message is sent to. PyMongo currently sends all getLastError messages to the admin db (the reasons are lost to history).

      Here's an example of this breaking in PyMongo master:

      >>> import pymongo
      >>> c = pymongo.Connection()
      >>> c.foo.authenticate('foo', 'pass')
      True
      >>> c.foo.foo.insert({'foo': 'bar'})
      ObjectId('4ffb5678fba5225a5c58b7ff')
      >>> c.foo.foo.find_one()
      {u'_id': ObjectId('4ffb5678fba5225a5c58b7ff'), u'foo': u'bar'}
      >>> c.foo.foo.insert({'foo': 'bim'}, safe=True)
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "pymongo/collection.py", line 306, in insert
          continue_on_error, self.__uuid_subtype), safe)
        File "pymongo/connection.py", line 742, in _send_message
          rv = self.__check_response_to_last_error(response)
        File "pymongo/connection.py", line 678, in __check_response_to_last_error
          helpers._check_command_response(error, self.disconnect)
        File "pymongo/helpers.py", line 129, in _check_command_response
          raise OperationFailure(msg % response["errmsg"])
      pymongo.errors.OperationFailure: need to login
      >>> for doc in c.foo.foo.find():
      ...     doc
      ... 
      {u'_id': ObjectId('4ffb5678fba5225a5c58b7ff'), u'foo': u'bar'}
      {u'_id': ObjectId('4ffb5687fba5225a5c58b800'), u'foo': u'bim'}
      

      Fix PyMongo so that getLastError is sent to the db the write operation was sent to.

      The workaround is to authenticate to the admin db for all operations.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: