PYTHON-696 - Fix user and index creation with old mongos versions.

This commit is contained in:
Bernie Hackett 2014-05-01 14:27:29 -07:00
parent 15511b70d8
commit b97b85f89a
3 changed files with 11 additions and 6 deletions

View File

@ -1052,7 +1052,7 @@ class Collection(common.BaseObject):
read_preference=ReadPreference.PRIMARY,
indexes=[index])
except OperationFailure, exc:
if exc.code in (59, None):
if exc.code in common.COMMAND_NOT_FOUND_CODES:
index["ns"] = self.__full_name
self.__database.system.indexes.insert(index, manipulate=False,
check_keys=False,

View File

@ -47,6 +47,14 @@ MAX_WRITE_BATCH_SIZE = 1000
MIN_SUPPORTED_WIRE_VERSION = 0
MAX_SUPPORTED_WIRE_VERSION = 2
# mongod/s 2.6 and above return code 59 when a
# command doesn't exist. mongod versions previous
# to 2.6 and mongos 2.4.x return no error code
# when a command does exist. mongos versions previous
# to 2.4.0 return code 13390 when a command does not
# exist.
COMMAND_NOT_FOUND_CODES = (59, 13390, None)
def raise_config_error(key, dummy):
"""Raise ConfigurationError with the given key name."""

View File

@ -779,11 +779,8 @@ class Database(common.BaseObject):
read_preference=ReadPreference.PRIMARY)
except OperationFailure, exc:
# MongoDB >= 2.5.3 requires the use of commands to manage
# users. "No such command" error didn't return an error
# code (59) before MongoDB 2.4.7 so we assume that an error
# code of None means the userInfo command doesn't exist and
# we should fall back to the legacy add user code.
if exc.code in (59, None):
# users.
if exc.code in common.COMMAND_NOT_FOUND_CODES:
self._legacy_add_user(name, password, read_only, **kwargs)
return
raise