[SERVER-58399] Duplicate errInfo field in write errors when operation fails document validation Created: 09/Jul/21  Updated: 29/Oct/23  Resolved: 11/Aug/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 5.0.0
Fix Version/s: 5.0.3, 5.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Patrick Freed Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by RUST-894 Unskip write_error::details test on s... Closed
Problem/Incident
causes CSHARP-3777 Temporary disable WriteError_details_... Closed
causes CSHARP-3785 Enable WriteError_details_should_expo... Closed
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.0
Sprint: QE 2021-08-09, QE 2021-08-23
Participants:

 Description   

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"
        }
      }
    }
  ]
}



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 12/Aug/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-58399 Fix serialization logic for 'errInfo' field produced by DocumentValidationError

(cherry picked from commit 74f795cdebd943bf8d6a56005dde4e2189cfb76e)
Branch: v5.0
https://github.com/mongodb/mongo/commit/6d73ddced9d9989aed01ac85b93155ec4b1876be

Comment by Githook User [ 11/Aug/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-58399 Fix serialization logic for 'errInfo' field produced by DocumentValidationError
Branch: master
https://github.com/mongodb/mongo/commit/74f795cdebd943bf8d6a56005dde4e2189cfb76e

Comment by Dmitry Lukyanov (Inactive) [ 31/Jul/21 ]

we see this issue in c# tests as well

Generated at Thu Feb 08 05:44:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.