When CDRIVER-1341 added logic to validate insert, replacement, and update documents (4b37e65), it subtly changed some conventions with bulk write execution. I was alerted to this through the PHP driver's manager-executeBulkWrite_error-005.phpt test. Validation errors are not reported until the bulk write is executed (here), which changes a previous assumption that execution would always ensure the server stream was initialized. The existing checks in mongoc_bulk_operation_execute() for valid client/database/collection objects could theoretically have returned within initializing a stream, but it wasn't a concern for us.
As it relates to the PHP driver, this means that we'd only be able to throw a BulkWriteException at execution time (from Manager::executeBulkWrite()) instead of an InvalidArgumentException from the offending method (e.g. BulkWrite::insert()). We actually discovered this because BulkWriteException attempts to refer to the server handling execution, and the selected server was null.
This may only be an issue for mongoc_bulk_operation_insert(), which may be at a disadvantage because it is void and cannot return a boolean indicating success or failure (unlike the update and replace "with_opts" functions). For this reason, I think we either need a new insert function that can return a boolean or some public API that can expose the mongoc_bulk_operation_t's error so that we can check it after each attempted insert. The update and replace functions have "with_opts" variants, which return a boolean indicating success or failure, as well as a bson_error_t * output argument to store any error encountered. A similar API for insert would be appreciated.
- is depended on by
-
PHPC-712 Driver should validate BSON documents before insert and update
- Closed
- is related to
-
CDRIVER-2017 Inconsistent error reporting for insert, update, and replace BSON validation
- Closed
-
PHPC-712 Driver should validate BSON documents before insert and update
- Closed