<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:16:11 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CDRIVER-2738] Bulk functions for insert, update, and replace should not support bypassDocumentValidation option</title>
                <link>https://jira.mongodb.org/browse/CDRIVER-2738</link>
                <project id="10030" key="CDRIVER">C Driver</project>
                    <description>&lt;p&gt;As part of &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-2373&quot; title=&quot;IDL for functions that take flexible options&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-2373&quot;&gt;&lt;del&gt;CDRIVER-2373&lt;/del&gt;&lt;/a&gt;, &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/db384740ed0f81c1a044f764e369fe8f26ce1438#diff-07530065537cb801310945d983664a6bR1115&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;db38474&lt;/a&gt; and &lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/ef63400925f5debd88464f2128b0ccf2599adfb6&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;ef63400&lt;/a&gt; added a &quot;bypassDocumentValidation&quot; option to the insert, update, and replace &lt;tt&gt;with_opts&lt;/tt&gt; functions in &lt;tt&gt;mongoc-bulk-operation.c&lt;/tt&gt;. This doesn&apos;t make sense, as &lt;tt&gt;mongoc_bulk_operation_t&lt;/tt&gt; already tracks &lt;tt&gt;bypass_document_validation&lt;/tt&gt; on its own. The bulk-level option is set at init time and applies to &lt;em&gt;all&lt;/em&gt; commands executed within the bulk.&lt;/p&gt;

&lt;p&gt;If we consider inserts, we can see that &lt;tt&gt;mongoc_bulk_operation_insert_with_opts()&lt;/tt&gt; calls &lt;tt&gt;_mongoc_bulk_insert_opts_parse()&lt;/tt&gt; to validate the options. Assuming that the &lt;tt&gt;bson_t *opts&lt;/tt&gt; argument is successfully parsed into &lt;tt&gt;_mongoc_bulk_insert_opts_t insert_opts&lt;/tt&gt;, only &lt;tt&gt;insert_opts.validate&lt;/tt&gt; is used later in the function. The other &lt;tt&gt;bypass&lt;/tt&gt; and &lt;tt&gt;extra&lt;/tt&gt; fields on that struct are completely ignored.&lt;/p&gt;

&lt;p&gt;There are now two paths: we either append to and existing &lt;tt&gt;insert&lt;/tt&gt; command or create a new one. If we append to an existing &lt;tt&gt;insert&lt;/tt&gt;, we delegate to &lt;tt&gt;_mongoc_write_command_insert_append()&lt;/tt&gt; and only pass the validated document. The &lt;tt&gt;bypass&lt;/tt&gt; option for &lt;tt&gt;insert_with_opts&lt;/tt&gt; has been ignored.&lt;/p&gt;

&lt;p&gt;Assuming we create a new &lt;tt&gt;insert&lt;/tt&gt; command, we delegate to &lt;tt&gt;&amp;#95;mongoc_write_command_init_insert&lt;/tt&gt; and pass our empty &lt;tt&gt;mongoc_write_command_t command&lt;/tt&gt; struct, the validated &lt;tt&gt;document&lt;/tt&gt; and &lt;tt&gt;bson_t *opts&lt;/tt&gt;, and our &lt;tt&gt;bulk-&amp;gt;flags&lt;/tt&gt; (which contains the original &quot;ordered&quot; and &quot;bypassDocumentValidation&quot; options used to create the &lt;tt&gt;mongoc_bulk_operation_t&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Jumping into &lt;tt&gt;mongoc-write-command.c&lt;/tt&gt;, &lt;tt&gt;&amp;#95;mongoc_write_command_init_insert()&lt;/tt&gt; delegates to &lt;tt&gt;&amp;#95;mongoc_write_command_init_bulk()&lt;/tt&gt; to initialize a &lt;tt&gt;mongoc_write_command_t command&lt;/tt&gt;. This function copies the &lt;tt&gt;cmd_opts&lt;/tt&gt; (originally &lt;tt&gt;bson_t *opts&lt;/tt&gt;) into the &lt;tt&gt;command-&amp;gt;cmd_opts&lt;/tt&gt; &lt;em&gt;and&lt;/em&gt; also assigns &lt;tt&gt;bulk-&amp;gt;flags&lt;/tt&gt; to &lt;tt&gt;command-&amp;gt;flags&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;Further down the line, &lt;tt&gt;&amp;#95;mongoc_write_opquery()&lt;/tt&gt; and &lt;tt&gt;&amp;#95;mongoc_write_opmsg()&lt;/tt&gt; will both end up calling &lt;tt&gt;&amp;#95;mongoc_write_command_init()&lt;/tt&gt;, which may end up appending &quot;bypassDocumentValidation&quot; into the command document again based on &lt;tt&gt;command-&amp;gt;flags&lt;/tt&gt;.&lt;/p&gt;

&lt;p&gt;I believe there are a few errors here:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;According to the CRUD spec, the &lt;a href=&quot;https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#bulk-write-models&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;bulk write models&lt;/a&gt; were never intended to support a &quot;bypassDocumentValidation&quot; option. That option is supported only on &lt;tt&gt;bulkWrite()&lt;/tt&gt; and other non-bulk methods (e.g. &lt;tt&gt;insertOne()&lt;/tt&gt;, &lt;tt&gt;updateMany()&lt;/tt&gt;).&lt;/li&gt;
	&lt;li&gt;The current behavior in libmongoc is prone to appending &quot;bypassDocumentValidation&quot; multiple times in some cases, and disregarding the &lt;tt&gt;mongoc_bulk_operation_t&lt;/tt&gt;-level option in other cases.&lt;/li&gt;
	&lt;li&gt;In the event that an inserted document is appended to an existing &lt;tt&gt;insert&lt;/tt&gt; command, the operation-level &quot;bypassDocumentValidation&quot; may be ignored entirely. This can be unexpected from the user&apos;s perspective, as it depends entirely on the order in which operations are added to a bulk.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Ideally, libmongoc should prohibit a &quot;bypassDocumentValidation&quot; option for functions that add insert, replace, and update operations to a bulk write.&lt;/p&gt;</description>
                <environment></environment>
        <key id="570471">CDRIVER-2738</key>
            <summary>Bulk functions for insert, update, and replace should not support bypassDocumentValidation option</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="13201">Fixed</resolution>
                                        <assignee username="jesse@mongodb.com">A. Jesse Jiryu Davis</assignee>
                                    <reporter username="jmikola@mongodb.com">Jeremy Mikola</reporter>
                        <labels>
                            <label>bulk</label>
                    </labels>
                <created>Wed, 11 Jul 2018 19:51:15 +0000</created>
                <updated>Sat, 28 Oct 2023 11:29:44 +0000</updated>
                            <resolved>Tue, 24 Jul 2018 18:52:12 +0000</resolved>
                                    <version>1.10.0</version>
                                    <fixVersion>1.13.0</fixVersion>
                                    <component>libmongoc</component>
                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="1955457" author="xgen-internal-githook" created="Tue, 24 Jul 2018 18:52:21 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;A. Jesse Jiryu Davis&apos;, &apos;email&apos;: &apos;jesse@mongodb.com&apos;, &apos;username&apos;: &apos;ajdavis&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CDRIVER-2738&quot; title=&quot;Bulk functions for insert, update, and replace should not support bypassDocumentValidation option&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CDRIVER-2738&quot;&gt;&lt;del&gt;CDRIVER-2738&lt;/del&gt;&lt;/a&gt; no bypassDocumentValidation option per bulk op&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-c-driver/commit/54d5e03d52556f65c1d1b092feb122b171593648&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-c-driver/commit/54d5e03d52556f65c1d1b092feb122b171593648&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1944794" author="jesse" created="Wed, 11 Jul 2018 20:03:27 +0000"  >&lt;p&gt;Agreed, Jeremy. Thanks for the report.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                                                <inwardlinks description="is related to">
                                        <issuelink>
            <issuekey id="458714">CDRIVER-2373</issuekey>
        </issuelink>
                            </inwardlinks>
                                    </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|htt6e7:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>