Skip to content

Commit 26a29ef

Browse files
committed
Revert "CDRIVER-2665 allow extra opts for bulk ops"
This reverts commit d061b31.
1 parent bc3c8f8 commit 26a29ef

File tree

5 files changed

+77
-100
lines changed

5 files changed

+77
-100
lines changed

build/generate-opts.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ def __init__(self, items, **defaults):
192192
write_concern_option,
193193
ordered_option,
194194
session_option,
195-
], ordered='true')),
195+
], allow_extra=False, ordered='true')),
196196

197197
('mongoc_bulk_insert_opts_t', Struct([
198198
validate_option,
199-
], validate='_mongoc_default_insert_vflags')),
199+
], validate='_mongoc_default_insert_vflags', allow_extra=False)),
200200

201201
('mongoc_bulk_update_opts_t', Shared([
202202
validate_option,
@@ -214,20 +214,23 @@ def __init__(self, items, **defaults):
214214
array_filters_option,
215215
],
216216
multi='false',
217-
validate='_mongoc_default_update_vflags')),
217+
validate='_mongoc_default_update_vflags',
218+
allow_extra=False)),
218219

219220
('mongoc_bulk_update_many_opts_t', Struct(
220221
[
221222
('update', {'type': 'mongoc_bulk_update_opts_t'}),
222223
array_filters_option,
223224
],
224225
multi='true',
225-
validate='_mongoc_default_update_vflags')),
226+
validate='_mongoc_default_update_vflags',
227+
allow_extra=False)),
226228

227229
('mongoc_bulk_replace_one_opts_t', Struct(
228230
[('update', {'type': 'mongoc_bulk_update_opts_t'})],
229231
multi='false',
230-
validate='_mongoc_default_replace_vflags')),
232+
validate='_mongoc_default_replace_vflags',
233+
allow_extra=False)),
231234

232235
('mongoc_bulk_remove_opts_t', Shared([
233236
collation_option,
@@ -236,11 +239,11 @@ def __init__(self, items, **defaults):
236239

237240
('mongoc_bulk_remove_one_opts_t', Struct([
238241
('remove', {'type': 'mongoc_bulk_remove_opts_t'}),
239-
], limit=1)),
242+
], limit=1, allow_extra=False)),
240243

241244
('mongoc_bulk_remove_many_opts_t', Struct([
242245
('remove', {'type': 'mongoc_bulk_remove_opts_t'}),
243-
], limit=0)),
246+
], limit=0, allow_extra=False)),
244247

245248
('mongoc_create_index_opts_t', Struct([
246249
write_concern_option,

build/opts_templates/mongoc-opts-private.h.template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef MONGOC_OPTS_H
22
#define MONGOC_OPTS_H
33

4-
#include <bson/bson.h>
4+
#include <bson.h>
55

6-
#include "mongoc/mongoc-client-session.h"
7-
#include "mongoc/mongoc-bulk-operation-private.h"
6+
#include "mongoc-client-session.h"
7+
#include "mongoc-bulk-operation-private.h"
88

99
{{ header_comment }}
1010

build/opts_templates/mongoc-opts.c.template

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "mongoc/mongoc-opts-helpers-private.h"
2-
#include "mongoc/mongoc-opts-private.h"
3-
#include "mongoc/mongoc-error.h"
4-
#include "mongoc/mongoc-util-private.h"
5-
#include "mongoc/mongoc-client-private.h"
1+
#include "mongoc-opts-helpers-private.h"
2+
#include "mongoc-opts-private.h"
3+
#include "mongoc-error.h"
4+
#include "mongoc-util-private.h"
5+
#include "mongoc-client-private.h"
66

77
{{ header_comment }}
88
{% for struct_type, description in opts_structs.items() %}

src/libmongoc/src/mongoc/mongoc-opts.c

Lines changed: 42 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -827,17 +827,12 @@ _mongoc_bulk_opts_parse (
827827
}
828828
}
829829
else {
830-
/* unrecognized values are copied to "extra" */
831-
if (!BSON_APPEND_VALUE (
832-
&mongoc_bulk_opts->extra,
833-
bson_iter_key (&iter),
834-
bson_iter_value (&iter))) {
835-
bson_set_error (error,
836-
MONGOC_ERROR_BSON,
837-
MONGOC_ERROR_BSON_INVALID,
838-
"Invalid 'opts' parameter.");
839-
return false;
840-
}
830+
bson_set_error (error,
831+
MONGOC_ERROR_COMMAND,
832+
MONGOC_ERROR_COMMAND_INVALID_ARG,
833+
"Invalid option '%s'",
834+
bson_iter_key (&iter));
835+
return false;
841836
}
842837
}
843838

@@ -888,17 +883,12 @@ _mongoc_bulk_insert_opts_parse (
888883
}
889884
}
890885
else {
891-
/* unrecognized values are copied to "extra" */
892-
if (!BSON_APPEND_VALUE (
893-
&mongoc_bulk_insert_opts->extra,
894-
bson_iter_key (&iter),
895-
bson_iter_value (&iter))) {
896-
bson_set_error (error,
897-
MONGOC_ERROR_BSON,
898-
MONGOC_ERROR_BSON_INVALID,
899-
"Invalid 'opts' parameter.");
900-
return false;
901-
}
886+
bson_set_error (error,
887+
MONGOC_ERROR_COMMAND,
888+
MONGOC_ERROR_COMMAND_INVALID_ARG,
889+
"Invalid option '%s'",
890+
bson_iter_key (&iter));
891+
return false;
902892
}
903893
}
904894

@@ -986,17 +976,12 @@ _mongoc_bulk_update_one_opts_parse (
986976
}
987977
}
988978
else {
989-
/* unrecognized values are copied to "extra" */
990-
if (!BSON_APPEND_VALUE (
991-
&mongoc_bulk_update_one_opts->extra,
992-
bson_iter_key (&iter),
993-
bson_iter_value (&iter))) {
994-
bson_set_error (error,
995-
MONGOC_ERROR_BSON,
996-
MONGOC_ERROR_BSON_INVALID,
997-
"Invalid 'opts' parameter.");
998-
return false;
999-
}
979+
bson_set_error (error,
980+
MONGOC_ERROR_COMMAND,
981+
MONGOC_ERROR_COMMAND_INVALID_ARG,
982+
"Invalid option '%s'",
983+
bson_iter_key (&iter));
984+
return false;
1000985
}
1001986
}
1002987

@@ -1086,17 +1071,12 @@ _mongoc_bulk_update_many_opts_parse (
10861071
}
10871072
}
10881073
else {
1089-
/* unrecognized values are copied to "extra" */
1090-
if (!BSON_APPEND_VALUE (
1091-
&mongoc_bulk_update_many_opts->extra,
1092-
bson_iter_key (&iter),
1093-
bson_iter_value (&iter))) {
1094-
bson_set_error (error,
1095-
MONGOC_ERROR_BSON,
1096-
MONGOC_ERROR_BSON_INVALID,
1097-
"Invalid 'opts' parameter.");
1098-
return false;
1099-
}
1074+
bson_set_error (error,
1075+
MONGOC_ERROR_COMMAND,
1076+
MONGOC_ERROR_COMMAND_INVALID_ARG,
1077+
"Invalid option '%s'",
1078+
bson_iter_key (&iter));
1079+
return false;
11001080
}
11011081
}
11021082

@@ -1176,17 +1156,12 @@ _mongoc_bulk_replace_one_opts_parse (
11761156
}
11771157
}
11781158
else {
1179-
/* unrecognized values are copied to "extra" */
1180-
if (!BSON_APPEND_VALUE (
1181-
&mongoc_bulk_replace_one_opts->extra,
1182-
bson_iter_key (&iter),
1183-
bson_iter_value (&iter))) {
1184-
bson_set_error (error,
1185-
MONGOC_ERROR_BSON,
1186-
MONGOC_ERROR_BSON_INVALID,
1187-
"Invalid 'opts' parameter.");
1188-
return false;
1189-
}
1159+
bson_set_error (error,
1160+
MONGOC_ERROR_COMMAND,
1161+
MONGOC_ERROR_COMMAND_INVALID_ARG,
1162+
"Invalid option '%s'",
1163+
bson_iter_key (&iter));
1164+
return false;
11901165
}
11911166
}
11921167

@@ -1245,17 +1220,12 @@ _mongoc_bulk_remove_one_opts_parse (
12451220
}
12461221
}
12471222
else {
1248-
/* unrecognized values are copied to "extra" */
1249-
if (!BSON_APPEND_VALUE (
1250-
&mongoc_bulk_remove_one_opts->extra,
1251-
bson_iter_key (&iter),
1252-
bson_iter_value (&iter))) {
1253-
bson_set_error (error,
1254-
MONGOC_ERROR_BSON,
1255-
MONGOC_ERROR_BSON_INVALID,
1256-
"Invalid 'opts' parameter.");
1257-
return false;
1258-
}
1223+
bson_set_error (error,
1224+
MONGOC_ERROR_COMMAND,
1225+
MONGOC_ERROR_COMMAND_INVALID_ARG,
1226+
"Invalid option '%s'",
1227+
bson_iter_key (&iter));
1228+
return false;
12591229
}
12601230
}
12611231

@@ -1314,17 +1284,12 @@ _mongoc_bulk_remove_many_opts_parse (
13141284
}
13151285
}
13161286
else {
1317-
/* unrecognized values are copied to "extra" */
1318-
if (!BSON_APPEND_VALUE (
1319-
&mongoc_bulk_remove_many_opts->extra,
1320-
bson_iter_key (&iter),
1321-
bson_iter_value (&iter))) {
1322-
bson_set_error (error,
1323-
MONGOC_ERROR_BSON,
1324-
MONGOC_ERROR_BSON_INVALID,
1325-
"Invalid 'opts' parameter.");
1326-
return false;
1327-
}
1287+
bson_set_error (error,
1288+
MONGOC_ERROR_COMMAND,
1289+
MONGOC_ERROR_COMMAND_INVALID_ARG,
1290+
"Invalid option '%s'",
1291+
bson_iter_key (&iter));
1292+
return false;
13281293
}
13291294
}
13301295

src/libmongoc/tests/test-mongoc-bulk.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ _test_opt (const char *opts_json, const char *msg)
234234
static void
235235
test_opts (void)
236236
{
237+
_test_opt ("{'foo': 1}", "Invalid option 'foo'");
237238
_test_opt ("{'writeConcern': 1}", "Invalid writeConcern");
238239
_test_opt ("{'writeConcern': {'w': 0, 'j': 1}}", "Invalid writeConcern");
239240
_test_opt ("{'sessionId': 'hi'}", "Invalid sessionId");
@@ -4450,14 +4451,19 @@ test_bulk_opts_parse (void)
44504451
MONGOC_ERROR_COMMAND_INVALID_ARG, \
44514452
"Invalid " _msg)
44524453

4454+
RM_ERR ("option 'foo'", remove_one, tmp_bson ("{'foo': 1}"));
4455+
RM_ERR ("option 'foo'", remove_many, tmp_bson ("{'foo': 1}"));
44534456
RM_ERR ("\"limit\" in opts: 2", remove_one, tmp_bson ("{'limit': 2}"));
44544457
RM_ERR ("\"limit\" in opts: 2", remove_many, tmp_bson ("{'limit': 2}"));
44554458
RM_ERR ("\"limit\" in opts: 0", remove_one, tmp_bson ("{'limit': 0}"));
44564459
RM_ERR ("\"limit\" in opts: 1", remove_many, tmp_bson ("{'limit': 1}"));
44574460

4461+
UPDATE_ERR ("option 'foo'", one, tmp_bson ("{'foo': 1}"));
4462+
UPDATE_ERR ("option 'foo'", many, tmp_bson ("{'foo': 1}"));
44584463
UPDATE_ERR ("\"multi\" in opts: true", one, tmp_bson ("{'multi': true}"));
44594464
UPDATE_ERR ("\"multi\" in opts: false", many, tmp_bson ("{'multi': false}"));
44604465

4466+
REPLACE_ERR ("option 'foo'", tmp_bson ("{'foo': 1}"));
44614467
REPLACE_ERR ("\"multi\": true in opts", tmp_bson ("{'multi': true}"));
44624468

44634469
#define NO_ERR(_fn, ...) \
@@ -4471,11 +4477,6 @@ test_bulk_opts_parse (void)
44714477
NO_ERR (update_one, q, u, tmp_bson ("{'multi': false}"));
44724478
NO_ERR (update_many, q, u, tmp_bson ("{'multi': true}"));
44734479
NO_ERR (replace_one, q, repl, tmp_bson ("{'multi': false}"));
4474-
NO_ERR (remove_one, q, tmp_bson ("{'foo': 1}"));
4475-
NO_ERR (remove_many, q, tmp_bson ("{'foo': 1}"));
4476-
NO_ERR (update_one, q, u, tmp_bson ("{'foo': 1}"));
4477-
NO_ERR (update_many, q, u, tmp_bson ("{'foo': 1}"));
4478-
NO_ERR (replace_one, q, repl, tmp_bson ("{'foo': 1}"));
44794480

44804481
mongoc_bulk_operation_destroy (bulk);
44814482
mongoc_collection_destroy (collection);
@@ -4518,23 +4519,31 @@ test_bulk_bypass_document_validation (void)
45184519
client = test_framework_client_new ();
45194520
collection = get_test_collection (client, "bypass_validation");
45204521

4521-
/* bypassDocumentValidation can be passed in opts, but is ignored */
4522+
/* bypassDocumentValidation can't be passed in opts */
45224523
bulk = mongoc_collection_create_bulk_operation_with_opts (
45234524
collection, tmp_bson ("{'bypassDocumentValidation': true}"));
45244525

45254526
i = mongoc_bulk_operation_execute (bulk, NULL, &error);
45264527
ASSERT_CMPUINT32 (i, ==, (uint32_t) 0);
4528+
ASSERT_ERROR_CONTAINS (error,
4529+
MONGOC_ERROR_COMMAND,
4530+
MONGOC_ERROR_COMMAND_INVALID_ARG,
4531+
"Invalid option 'bypassDocumentValidation'");
45274532

45284533
mongoc_bulk_operation_destroy (bulk);
45294534

4530-
/* same for insert opts */
4535+
/* not allowed in insert opts either */
45314536
bulk = mongoc_collection_create_bulk_operation_with_opts (collection, NULL);
45324537
r = mongoc_bulk_operation_insert_with_opts (
45334538
bulk,
45344539
tmp_bson ("{}"),
45354540
tmp_bson ("{'bypassDocumentValidation': true}"),
45364541
&error);
4537-
BSON_ASSERT (r);
4542+
BSON_ASSERT (!r);
4543+
ASSERT_ERROR_CONTAINS (error,
4544+
MONGOC_ERROR_COMMAND,
4545+
MONGOC_ERROR_COMMAND_INVALID_ARG,
4546+
"Invalid option 'bypassDocumentValidation'");
45384547

45394548
mongoc_bulk_operation_destroy (bulk);
45404549
mongoc_collection_destroy (collection);

0 commit comments

Comments
 (0)