-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
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.