Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-58399

Duplicate errInfo field in write errors when operation fails document validation

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.3, 5.1.0-rc0
    • Affects Version/s: 5.0.0
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • v5.0
    • QE 2021-08-09, QE 2021-08-23

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

            Assignee:
            mihai.andrei@mongodb.com Mihai Andrei
            Reporter:
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: