Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-5856

mongoc_bulkwritereturn_t destroys result for acknowledged write with no successful results

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 1.28.0
    • Component/s: Bulk API
    • None
    • Not Needed
    • C Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      When modeling BulkWriteCommandResult (PHPC-2494), I was relying on mongoc_bulkwritereturn_t.res being non-null to infer whether the write was acknowledged since there is no other indication on mongoc_bulkwritereturn_t.

      However, mongoc_bulkwrite_execute has a condition that destroys mongoc_bulkwritereturn_t.res when (!is_acknowledged || !has_successful_results).

      I'm not sure if this is intentional, but I wanted to make a note of it in case it was not. I think most users would expect there to be a result object (even empty) for any acknowledged write, although I'm also not sure if that is explicitly discussed in the bulk write spec.

      In the meantime, I will revert to explicitly checking a write concern struct (either the explicit option or whatever is inherited by the client).

      How to Reproduce

      I observed this when constructing a test for bypassDocumentValidation that failed with a single insert. I used the following create command to define a basic validation rule requiring an "x" field:

      {
          "create": "coll",
          "validator": {
              "$jsonSchema": {
                  "bsonType": "object",
                  "required": ["x"]
              }
          }
      }
      

      I then constructed a mongoc_bulkwrite_t with bypassDocumentValidation: true and attempted to insert one invalid document without an "x" field.

      The resulting mongoc_bulkwritereturn_t struct has a null res field due to a (!is_acknowledged || !has_successful_results) condition near the bottom of mongoc_bulkwrite_execute.

      Note: I attempted to produce a single file derived from example-bulkwrite.c, but attempting to compile that locally through my libmongoc submodule was a bit too time consuming given how trivial I expect this will be for a libmongoc engineer to repro on their own.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: