When a write operation fails document validation, the write error associated with the operation contains the errInfo field twice with identical information. This may cause drivers to fail to deserialize the response.
This appears to only affect sharded clusters.
version:
mongos version v5.0.0-alpha0-1474-ge1f9a39 Build Info: { "version": "5.0.0-alpha0-1474-ge1f9a39", "gitVersion": "e1f9a3922d20886691e4c22c4fa63ba81a89b3d7", "openSSLVersion": "OpenSSL 1.1.1f 31 Mar 2020", "modules": [ "enterprise" ], "allocator": "tcmalloc", "environment": { "distmod": "ubuntu2004", "distarch": "x86_64", "target_arch": "x86_64" } }
Note: this does not appear to affect 5.0.0 (git version 1184f004a99660de6f5e745573419bda8a28c0e9).
To reproduce, create a collection with a schema validator, fail the validation, and inspect the raw BSON of the response.
e.g. the output when using the C driver:
uri = mongoc_uri_new_with_error(uri_string, &error); if (!uri) { fprintf(stderr, "failed to parse URI: %s\n" "error message: %s\n", uri_string, error.message); return EXIT_FAILURE; } mongoc_client_t *client = mongoc_client_new_from_uri(uri); mongoc_database_t *database = mongoc_client_get_database(client, "write_error_details"); mongoc_collection_t *collection = mongoc_database_get_collection(database, "test"); bson_t *reply = bson_new(); mongoc_collection_insert_one(collection, BCON_NEW ("x", BCON_INT32(1)), NULL, reply, NULL); printf("%s\n", bson_as_relaxed_extended_json(reply, NULL));
prints
{ "insertedCount": 0, "writeErrors": [ { "index": 0, "code": 121, "codeName": "DocumentValidationFailure", "errmsg": "Document failed validation", "errInfo": { "failingDocumentId": { "$oid": "60e875e7dedaa12434510392" }, "details": { "operatorName": "$type", "specifiedAs": { "x": { "$type": "string" } }, "reason": "type did not match", "consideredValue": 1, "consideredType": "int" } }, "errInfo": { "failingDocumentId": { "$oid": "60e875e7dedaa12434510392" }, "details": { "operatorName": "$type", "specifiedAs": { "x": { "$type": "string" } }, "reason": "type did not match", "consideredValue": 1, "consideredType": "int" } } } ] }
- causes
-
CSHARP-3777 Temporary disable WriteError_details_should_expose_writeErrors_errInfo due to the server bug
- Closed
-
CSHARP-3785 Enable WriteError_details_should_expose_writeErrors_errInfo test on latest sharded
- Closed
- is depended on by
-
RUST-894 Unskip write_error::details test on sharded clusters
- Closed