Skip to content

Commit 0f572c8

Browse files
eramongodbkevinAlbs
authored andcommitted
CDRIVER-4415 Allow bulkWriteResult to be optional (#1047)
1 parent 4bb570a commit 0f572c8

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/libmongoc/doc/mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Synopsis
1515
1616
Get the bulk write result set by a successful call to :symbol:`mongoc_client_encryption_rewrap_many_datakey()`.
1717

18+
Returns ``NULL`` if no bulk write operation was executed or if the bulk write operation was unacknowledged.
19+
1820
Parameters
1921
----------
2022

src/libmongoc/src/mongoc/mongoc-client-side-encryption.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,12 @@ mongoc_client_encryption_rewrap_many_datakey_result_get_bulk_write_result (
528528
return NULL;
529529
}
530530

531+
/* bulkWriteResult may be empty if no result of a bulk write operation has
532+
* been assigned to it. Treat as equivalent to an unset optional state. */
533+
if (bson_empty (&result->bulk_write_result)) {
534+
return NULL;
535+
}
536+
531537
return &result->bulk_write_result;
532538
}
533539

src/libmongoc/tests/json/client_side_encryption/unified/rewrapManyDataKey.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,9 @@
266266
}
267267
},
268268
"expectResult": {
269-
"bulkWriteResult": {}
269+
"bulkWriteResult": {
270+
"$$exists": false
271+
}
270272
}
271273
}
272274
],

src/libmongoc/tests/unified/operation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ operation_rewrap_many_data_key (test_t *test,
350350

351351
bson_t doc = BSON_INITIALIZER;
352352

353-
{
353+
if (bulk_write_result) {
354354
bson_t *const rewritten =
355355
rewrite_bulk_write_result (bulk_write_result);
356356
BSON_APPEND_DOCUMENT (&doc, "bulkWriteResult", rewritten);

0 commit comments

Comments
 (0)