[CDRIVER-2738] Bulk functions for insert, update, and replace should not support bypassDocumentValidation option Created: 11/Jul/18 Updated: 28/Oct/23 Resolved: 24/Jul/18 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | libmongoc |
| Affects Version/s: | 1.10.0 |
| Fix Version/s: | 1.13.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Jeremy Mikola | Assignee: | A. Jesse Jiryu Davis |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | bulk | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
As part of If we consider inserts, we can see that mongoc_bulk_operation_insert_with_opts() calls _mongoc_bulk_insert_opts_parse() to validate the options. Assuming that the bson_t *opts argument is successfully parsed into _mongoc_bulk_insert_opts_t insert_opts, only insert_opts.validate is used later in the function. The other bypass and extra fields on that struct are completely ignored. There are now two paths: we either append to and existing insert command or create a new one. If we append to an existing insert, we delegate to _mongoc_write_command_insert_append() and only pass the validated document. The bypass option for insert_with_opts has been ignored. Assuming we create a new insert command, we delegate to _mongoc_write_command_init_insert and pass our empty mongoc_write_command_t command struct, the validated document and bson_t *opts, and our bulk->flags (which contains the original "ordered" and "bypassDocumentValidation" options used to create the mongoc_bulk_operation_t. Jumping into mongoc-write-command.c, _mongoc_write_command_init_insert() delegates to _mongoc_write_command_init_bulk() to initialize a mongoc_write_command_t command. This function copies the cmd_opts (originally bson_t *opts) into the command->cmd_opts and also assigns bulk->flags to command->flags. Further down the line, _mongoc_write_opquery() and _mongoc_write_opmsg() will both end up calling _mongoc_write_command_init(), which may end up appending "bypassDocumentValidation" into the command document again based on command->flags. I believe there are a few errors here:
Ideally, libmongoc should prohibit a "bypassDocumentValidation" option for functions that add insert, replace, and update operations to a bulk write. |
| Comments |
| Comment by Githook User [ 24/Jul/18 ] |
|
Author: {'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}Message: |
| Comment by A. Jesse Jiryu Davis [ 11/Jul/18 ] |
|
Agreed, Jeremy. Thanks for the report. |