From 70aaf0dc52ba249ae25c92cdc32e75d849497a7a Mon Sep 17 00:00:00 2001 From: Bernie Hackett Date: Wed, 24 Sep 2014 13:55:08 -0700 Subject: [PATCH] PYTHON-739 - Add namespace to command failure message. --- pymongo/database.py | 3 ++- pymongo/mongo_client.py | 6 ++++-- pymongo/mongo_replica_set_client.py | 6 ++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pymongo/database.py b/pymongo/database.py index ea74d1396..024ed1272 100644 --- a/pymongo/database.py +++ b/pymongo/database.py @@ -348,7 +348,8 @@ class Database(common.BaseObject): result = doc if check: - msg = "command %s failed: %%s" % repr(command).replace("%", "%%") + msg = "command %s on namespace %s failed: %%s" % ( + repr(command).replace("%", "%%"), self.name + '.$cmd') helpers._check_command_response(result, self.connection.disconnect, msg, allowable_errors) diff --git a/pymongo/mongo_client.py b/pymongo/mongo_client.py index 2390f5896..2569a1b8e 100644 --- a/pymongo/mongo_client.py +++ b/pymongo/mongo_client.py @@ -675,7 +675,8 @@ class MongoClient(common.BaseObject): def __simple_command(self, sock_info, dbname, spec): """Send a command to the server. May raise AutoReconnect. """ - rqst_id, msg, _ = message.query(0, dbname + '.$cmd', 0, -1, spec) + ns = dbname + '.$cmd' + rqst_id, msg, _ = message.query(0, ns, 0, -1, spec) start = time.time() try: sock_info.sock.sendall(msg) @@ -689,7 +690,8 @@ class MongoClient(common.BaseObject): end = time.time() response = helpers._unpack_response(response)['data'][0] - msg = "command %s failed: %%s" % repr(spec).replace("%", "%%") + msg = "command %s on namespace %s failed: %%s" % ( + repr(spec).replace("%", "%%"), ns) helpers._check_command_response(response, None, msg) return response, end - start diff --git a/pymongo/mongo_replica_set_client.py b/pymongo/mongo_replica_set_client.py index 00a45b018..c96d6af69 100644 --- a/pymongo/mongo_replica_set_client.py +++ b/pymongo/mongo_replica_set_client.py @@ -1011,7 +1011,8 @@ class MongoReplicaSetClient(common.BaseObject): """Send a command to the server. Returns (response, ping_time in seconds). """ - rqst_id, msg, _ = message.query(0, dbname + '.$cmd', 0, -1, spec) + ns = dbname + '.$cmd' + rqst_id, msg, _ = message.query(0, ns, 0, -1, spec) start = time.time() try: sock_info.sock.sendall(msg) @@ -1022,7 +1023,8 @@ class MongoReplicaSetClient(common.BaseObject): end = time.time() response = helpers._unpack_response(response)['data'][0] - msg = "command %s failed: %%s" % repr(spec).replace("%", "%%") + msg = "command %s on namespace %s failed: %%s" % ( + repr(spec).replace("%", "%%"), ns) helpers._check_command_response(response, None, msg) return response, end - start