diff --git a/pymongo/helpers_shared.py b/pymongo/helpers_shared.py index c3611df7c8..1ba69876e9 100644 --- a/pymongo/helpers_shared.py +++ b/pymongo/helpers_shared.py @@ -240,15 +240,6 @@ def _check_command_response( return details = response - # Mongos returns the error details in a 'raw' object - # for some errors. - if "raw" in response: - for shard in response["raw"].values(): - # Grab the first non-empty raw error from a shard. - if shard.get("errmsg") and not shard.get("ok"): - details = shard - break - errmsg = details["errmsg"] code = details.get("code") diff --git a/test/asynchronous/test_database.py b/test/asynchronous/test_database.py index 3afdc230ef..22213d6e8a 100644 --- a/test/asynchronous/test_database.py +++ b/test/asynchronous/test_database.py @@ -617,36 +617,6 @@ def test_command_response_without_ok(self): else: self.fail("_check_command_response didn't raise OperationFailure") - def test_mongos_response(self): - error_document = { - "ok": 0, - "errmsg": "outer", - "raw": {"shard0/host0,host1": {"ok": 0, "errmsg": "inner"}}, - } - - with self.assertRaises(OperationFailure) as context: - helpers_shared._check_command_response(error_document, None) - - self.assertIn("inner", str(context.exception)) - - # If a shard has no primary and you run a command like dbstats, which - # cannot be run on a secondary, mongos's response includes empty "raw" - # errors. See SERVER-15428. - error_document = {"ok": 0, "errmsg": "outer", "raw": {"shard0/host0,host1": {}}} - - with self.assertRaises(OperationFailure) as context: - helpers_shared._check_command_response(error_document, None) - - self.assertIn("outer", str(context.exception)) - - # Raw error has ok: 0 but no errmsg. Not a known case, but test it. - error_document = {"ok": 0, "errmsg": "outer", "raw": {"shard0/host0,host1": {"ok": 0}}} - - with self.assertRaises(OperationFailure) as context: - helpers_shared._check_command_response(error_document, None) - - self.assertIn("outer", str(context.exception)) - @async_client_context.require_test_commands @async_client_context.require_no_mongos async def test_command_max_time_ms(self): diff --git a/test/test_database.py b/test/test_database.py index 20ac55b6eb..2f6c312f50 100644 --- a/test/test_database.py +++ b/test/test_database.py @@ -612,36 +612,6 @@ def test_command_response_without_ok(self): else: self.fail("_check_command_response didn't raise OperationFailure") - def test_mongos_response(self): - error_document = { - "ok": 0, - "errmsg": "outer", - "raw": {"shard0/host0,host1": {"ok": 0, "errmsg": "inner"}}, - } - - with self.assertRaises(OperationFailure) as context: - helpers_shared._check_command_response(error_document, None) - - self.assertIn("inner", str(context.exception)) - - # If a shard has no primary and you run a command like dbstats, which - # cannot be run on a secondary, mongos's response includes empty "raw" - # errors. See SERVER-15428. - error_document = {"ok": 0, "errmsg": "outer", "raw": {"shard0/host0,host1": {}}} - - with self.assertRaises(OperationFailure) as context: - helpers_shared._check_command_response(error_document, None) - - self.assertIn("outer", str(context.exception)) - - # Raw error has ok: 0 but no errmsg. Not a known case, but test it. - error_document = {"ok": 0, "errmsg": "outer", "raw": {"shard0/host0,host1": {"ok": 0}}} - - with self.assertRaises(OperationFailure) as context: - helpers_shared._check_command_response(error_document, None) - - self.assertIn("outer", str(context.exception)) - @client_context.require_test_commands @client_context.require_no_mongos def test_command_max_time_ms(self):