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

Don't send empty writeConcern to user management commands (v2.9)

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

      When creating users through Database.add_user, PyMongo 2.x will add an empty dict as the value for writeConcern in the createUser command if the application hasn't changed the default write concern. This causes mongos (but not mongod) to return an error:

      >>> c = pymongo.MongoClient()
      >>> c.admin.command('createUser', 'user1', pwd='foobar1', roles=['root'], digestPassword=True, writeConcern={})
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "pymongo/database.py", line 533, in command
          codec_options, **kwargs)[0]
        File "pymongo/database.py", line 438, in _command
          result, self.connection._disconnect, None, allowable_errors)
        File "pymongo/helpers.py", line 213, in _check_command_response
          raise OperationFailure(msg % errmsg, code, response)
      pymongo.errors.OperationFailure: write concern object cannot be empty
      >>> c.admin.command('ismaster')['msg']
      u'isdbgrid'
      >>> c.admin.add_user('user1', 'foobar1')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "pymongo/database.py", line 964, in add_user
          (not uinfo["users"]), name, password, read_only, **kwargs)
        File "pymongo/database.py", line 890, in _create_or_update_user
          read_preference=ReadPreference.PRIMARY, **opts)
        File "pymongo/database.py", line 533, in command
          codec_options, **kwargs)[0]
        File "pymongo/database.py", line 438, in _command
          result, self.connection._disconnect, None, allowable_errors)
        File "pymongo/helpers.py", line 213, in _check_command_response
          raise OperationFailure(msg % errmsg, code, response)
      pymongo.errors.OperationFailure: write concern object cannot be empty
      

      The problem seems to exist with MongoDB 3.2+. For some reason this problem isn't reproducible in our Jenkins CI infrastructure, but it is reproducible in Evergreen and on my local machine.

      The solution is simple. Don't send an empty writeConcern for user management commands.

            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: