Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions pymongo/helpers_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Comment on lines 242 to 244

Expand Down
30 changes: 0 additions & 30 deletions test/asynchronous/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
30 changes: 0 additions & 30 deletions test/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading