PYTHON-3351 Provide access to raw result document when the server returns an error for a command (#1125)

This commit is contained in:
Julius Park 2022-12-02 12:52:01 -08:00 committed by GitHub
parent 26efc0f43d
commit ccade9bc05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 576 additions and 3 deletions

View File

@ -0,0 +1,90 @@
{
"description": "aggregate-merge-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1,
"x": 1
},
{
"_id": 2,
"x": 1
}
]
}
],
"tests": [
{
"description": "aggregate $merge DuplicateKey error is accessible",
"runOnRequirements": [
{
"minServerVersion": "5.1",
"topologies": [
"single",
"replicaset"
]
}
],
"operations": [
{
"name": "aggregate",
"object": "database0",
"arguments": {
"pipeline": [
{
"$documents": [
{
"_id": 2,
"x": 1
}
]
},
{
"$merge": {
"into": "test",
"whenMatched": "fail"
}
}
]
},
"expectError": {
"errorCode": 11000,
"errorResponse": {
"keyPattern": {
"_id": 1
},
"keyValue": {
"_id": 2
}
}
}
}
]
}
]
}

View File

@ -0,0 +1,88 @@
{
"description": "bulkWrite-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": false
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "bulkWrite operations support errorResponse assertions",
"runOnRequirements": [
{
"minServerVersion": "4.0.0",
"topologies": [
"single",
"replicaset"
]
},
{
"minServerVersion": "4.2.0",
"topologies": [
"sharded"
]
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"insert"
],
"errorCode": 8
}
}
}
},
{
"name": "bulkWrite",
"object": "collection0",
"arguments": {
"requests": [
{
"insertOne": {
"document": {
"_id": 1
}
}
}
]
},
"expectError": {
"errorCode": 8,
"errorResponse": {
"code": 8
}
}
}
]
}
]
}

View File

@ -0,0 +1,82 @@
{
"description": "deleteOne-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": false
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "delete operations support errorResponse assertions",
"runOnRequirements": [
{
"minServerVersion": "4.0.0",
"topologies": [
"single",
"replicaset"
]
},
{
"minServerVersion": "4.2.0",
"topologies": [
"sharded"
]
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"delete"
],
"errorCode": 8
}
}
}
},
{
"name": "deleteOne",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
}
},
"expectError": {
"errorCode": 8,
"errorResponse": {
"code": 8
}
}
}
]
}
]
}

View File

@ -64,7 +64,11 @@
"key": "value"
}
},
"expectResult": [ 11, 22, 33 ]
"expectResult": [
11,
22,
33
]
}
],
"expectEvents": [
@ -105,7 +109,11 @@
"filter": {},
"comment": "comment"
},
"expectResult": [ 11, 22, 33 ]
"expectResult": [
11,
22,
33
]
}
],
"expectEvents": [

View File

@ -0,0 +1,132 @@
{
"description": "findOneAndUpdate-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0"
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"initialData": [
{
"collectionName": "test",
"databaseName": "crud-tests",
"documents": [
{
"_id": 1,
"x": "foo"
}
]
}
],
"tests": [
{
"description": "findOneAndUpdate DuplicateKey error is accessible",
"runOnRequirements": [
{
"minServerVersion": "4.2"
}
],
"operations": [
{
"name": "createIndex",
"object": "collection0",
"arguments": {
"keys": {
"x": 1
},
"unique": true
}
},
{
"name": "findOneAndUpdate",
"object": "collection0",
"arguments": {
"filter": {
"_id": 2
},
"update": {
"$set": {
"x": "foo"
}
},
"upsert": true
},
"expectError": {
"errorCode": 11000,
"errorResponse": {
"keyPattern": {
"x": 1
},
"keyValue": {
"x": "foo"
}
}
}
}
]
},
{
"description": "findOneAndUpdate document validation errInfo is accessible",
"runOnRequirements": [
{
"minServerVersion": "5.0"
}
],
"operations": [
{
"name": "modifyCollection",
"object": "database0",
"arguments": {
"collection": "test",
"validator": {
"x": {
"$type": "string"
}
}
}
},
{
"name": "findOneAndUpdate",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$set": {
"x": 1
}
}
},
"expectError": {
"errorCode": 121,
"errorResponse": {
"errInfo": {
"failingDocumentId": 1,
"details": {
"$$type": "object"
}
}
}
}
}
]
}
]
}

View File

@ -0,0 +1,82 @@
{
"description": "insertOne-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": false
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "insert operations support errorResponse assertions",
"runOnRequirements": [
{
"minServerVersion": "4.0.0",
"topologies": [
"single",
"replicaset"
]
},
{
"minServerVersion": "4.2.0",
"topologies": [
"sharded"
]
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"insert"
],
"errorCode": 8
}
}
}
},
{
"name": "insertOne",
"object": "collection0",
"arguments": {
"document": {
"_id": 1
}
},
"expectError": {
"errorCode": 8,
"errorResponse": {
"code": 8
}
}
}
]
}
]
}

View File

@ -0,0 +1,87 @@
{
"description": "updateOne-errorResponse",
"schemaVersion": "1.12",
"createEntities": [
{
"client": {
"id": "client0",
"useMultipleMongoses": false
}
},
{
"database": {
"id": "database0",
"client": "client0",
"databaseName": "crud-tests"
}
},
{
"collection": {
"id": "collection0",
"database": "database0",
"collectionName": "test"
}
}
],
"tests": [
{
"description": "update operations support errorResponse assertions",
"runOnRequirements": [
{
"minServerVersion": "4.0.0",
"topologies": [
"single",
"replicaset"
]
},
{
"minServerVersion": "4.2.0",
"topologies": [
"sharded"
]
}
],
"operations": [
{
"name": "failPoint",
"object": "testRunner",
"arguments": {
"client": "client0",
"failPoint": {
"configureFailPoint": "failCommand",
"mode": {
"times": 1
},
"data": {
"failCommands": [
"update"
],
"errorCode": 8
}
}
}
},
{
"name": "updateOne",
"object": "collection0",
"arguments": {
"filter": {
"_id": 1
},
"update": {
"$set": {
"x": 1
}
}
},
"expectError": {
"errorCode": 8,
"errorResponse": {
"code": 8
}
}
}
]
}
]
}

View File

@ -862,7 +862,7 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
a class attribute ``TEST_SPEC``.
"""
SCHEMA_VERSION = Version.from_string("1.10")
SCHEMA_VERSION = Version.from_string("1.12")
RUN_ON_LOAD_BALANCER = True
RUN_ON_SERVERLESS = True
TEST_SPEC: Any
@ -994,6 +994,10 @@ class UnifiedSpecTestMixinV1(IntegrationTest):
error_labels_contain = spec.get("errorLabelsContain")
error_labels_omit = spec.get("errorLabelsOmit")
expect_result = spec.get("expectResult")
error_response = spec.get("errorResponse")
if error_response:
for k in error_response.keys():
self.assertEqual(error_response[k], exception.details[k])
if is_error:
# already satisfied because exception was raised