diff options
author | ali-mir <ali.mir@mongodb.com> | 2022-02-02 22:53:03 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-02-22 17:20:40 +0000 |
commit | cbafc6750da5cdc228525868dd07c4c14e2ae44b (patch) | |
tree | 2f489dfbc9b1ba808969b9f61a67d62ccfdeff83 | |
parent | 581dc1ab9dfb0677a8ea27be6c697f3311f4ba20 (diff) | |
download | mongo-cbafc6750da5cdc228525868dd07c4c14e2ae44b.tar.gz |
SERVER-62569 Handle bson_serialization_type for ArrayType in IDL Compatibility Checker script
(cherry picked from commit a259083f1162f96b8380808b6c2fc6e4551130b4)
3 files changed, 94 insertions, 4 deletions
diff --git a/buildscripts/idl/idl_check_compatibility.py b/buildscripts/idl/idl_check_compatibility.py index 6e0e679720d..93d2919bfdd 100644 --- a/buildscripts/idl/idl_check_compatibility.py +++ b/buildscripts/idl/idl_check_compatibility.py @@ -512,8 +512,10 @@ def check_reply_fields(ctxt: IDLCompatibilityContext, old_reply: syntax.Struct, allow_name: str = cmd_name + "-reply-" + new_field.name new_field_type = get_field_type(new_field, new_idl_file, new_idl_file_path) - if isinstance(new_field_type, - syntax.Type) and "any" in new_field_type.bson_serialization_type: + # If we encounter a bson_serialization_type of None, we skip checking if 'any' is used. + if isinstance( + new_field_type, syntax.Type + ) and new_field_type.bson_serialization_type is not None and "any" in new_field_type.bson_serialization_type: # If 'any' is not explicitly allowed as the bson_serialization_type. if allow_name not in ALLOW_ANY_TYPE_LIST: ctxt.add_reply_field_bson_any_not_allowed_error( @@ -752,8 +754,10 @@ def check_command_params_or_type_struct_fields( if newly_added: allow_name: str = cmd_name + "-param-" + new_field.name if is_command_parameter else cmd_name new_field_type = get_field_type(new_field, new_idl_file, new_idl_file_path) - if isinstance(new_field_type, - syntax.Type) and "any" in new_field_type.bson_serialization_type: + # If we encounter a bson_serialization_type of None, we skip checking if 'any' is used. + if isinstance( + new_field_type, syntax.Type + ) and new_field_type.bson_serialization_type is not None and "any" in new_field_type.bson_serialization_type: # If 'any' is not explicitly allowed as the bson_serialization_type. if allow_name not in ALLOW_ANY_TYPE_LIST: ctxt.add_command_or_param_type_bson_any_not_allowed_error( diff --git a/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl b/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl index 018d8ddcd01..70c810f529b 100644 --- a/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl +++ b/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl @@ -412,6 +412,28 @@ structs: ArrayCommandParameter: type: array<string> + ReplyWithNewArrayTypeField: + description: "new field is of ArrayType" + fields: + ok: + type: bool + unstable: false + newArrayTypeField: + type: array<int> + optional: true + unstable: false + + ReplyWithNewNestedArrayTypeField: + description: "new field is a struct with a field of ArrayType" + fields: + ok: + type: bool + unstable: false + newStructWithArrayTypeField: + type: ArrayTypeStruct + optional: true + unstable: false + commands: testCommand: description: "new passing test command, there was no change from the old version" @@ -1380,3 +1402,33 @@ commands: reply_type: OkReply access_check: none: true + + commandWithNewArrayTypeParameterAndArrayTypeReply: + description: "new command adds a new ArrayType parameter and a reply type with an ArrayType" + command_name: commandWithNewArrayTypeParameterAndArrayTypeReply + namespace: type + type: array<int> + cpp_name: commandWithNewArrayTypeParameterAndArrayTypeReply + strict: true + api_version: "1" + fields: + newArrayTypeParameter: + type: array<int> + optional: true + unstable: false + reply_type: ReplyWithNewArrayTypeField + + commandWithNewNestedArrayTypeParameterAndNestedArrayTypeReply: + description: "new command adds a new parameter with a nested ArrayType field and a reply type with a nested ArrayType" + command_name: commandWithNewNestedArrayTypeParameterAndNestedArrayTypeReply + namespace: type + type: ArrayTypeStruct + cpp_name: commandWithNewNestedArrayTypeParameterAndNestedArrayTypeReply + strict: true + api_version: "1" + fields: + newNestedArrayTypeParameter: + type: ArrayTypeStruct + optional: true + unstable: false + reply_type: ReplyWithNewNestedArrayTypeField
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl b/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl index 5c7535c3e23..5c2a24cbbcb 100644 --- a/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl +++ b/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl @@ -400,6 +400,20 @@ structs: ArrayCommandParameter: type: array<string> + ReplyWithNewArrayTypeField: + description: "new field is of ArrayType" + fields: + ok: + type: bool + unstable: false + + ReplyWithNewNestedArrayTypeField: + description: "new field is a struct with a field of ArrayType" + fields: + ok: + type: bool + unstable: false + commands: testCommand: description: "old passing test command" @@ -1366,3 +1380,23 @@ commands: strict: true api_version: "" reply_type: OkReply + + commandWithNewArrayTypeParameterAndArrayTypeReply: + description: "new command adds a new ArrayType parameter and a reply type with an ArrayType" + command_name: commandWithNewArrayTypeParameterAndArrayTypeReply + namespace: type + type: array<int> + cpp_name: commandWithNewArrayTypeParameterAndArrayTypeReply + strict: true + api_version: "1" + reply_type: ReplyWithNewArrayTypeField + + commandWithNewNestedArrayTypeParameterAndNestedArrayTypeReply: + description: "new command adds a new parameter with a nested ArrayType field and a reply type with a nested ArrayType" + command_name: commandWithNewNestedArrayTypeParameterAndNestedArrayTypeReply + namespace: type + type: ArrayTypeStruct + cpp_name: commandWithNewNestedArrayTypeParameterAndNestedArrayTypeReply + strict: true + api_version: "1" + reply_type: ReplyWithNewNestedArrayTypeField
\ No newline at end of file |