From 05aa788ed700172eb86c9bd657c73d5c7f08385d Mon Sep 17 00:00:00 2001 From: kai ru Date: Tue, 4 Mar 2025 13:26:14 +0800 Subject: [PATCH 1/2] Fix resources merge for generic update command with optional query params of get path checked --- .../command/controller/workspace_cfg_editor.py | 12 ++++++++++-- .../command/model/configuration/_arg_builder.py | 7 +++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/aaz_dev/command/controller/workspace_cfg_editor.py b/src/aaz_dev/command/controller/workspace_cfg_editor.py index a969fac2..3cd23f0e 100644 --- a/src/aaz_dev/command/controller/workspace_cfg_editor.py +++ b/src/aaz_dev/command/controller/workspace_cfg_editor.py @@ -218,8 +218,6 @@ def merge(self, plus_cfg_editor): arg_group = plus_cfg_editor._filter_args_in_arg_group(arg_group, new_args, copy=True) if arg_group: plus_resources_arg_groups.append(arg_group) - - if method in plus_operations_by_method: assert len(plus_operations_by_method[method]) == len(plus_cfg_editor.resources) @@ -248,6 +246,16 @@ def merge(self, plus_cfg_editor): plus_operation.http.request.header = operation.http.request.header plus_operation.http.request.body = operation.http.request.body plus_operation.http.responses = operation.http.responses + if operation.http.request.method.lower() == 'get': + # the get method in generate update command will ignore the optional query params if it's not exist in the put or patch operations. + # here we need to exclude them if those query params has args in the main command + params = [] + for param in plus_operation.http.request.query.params: + arg, _ = main_editor.find_arg_in_command_by_var(main_command, arg_var=param.arg) + if not param.required and not arg: + continue + params.append(param) + plus_operation.http.request.query.params = params plus_operation = plus_operation.__class__(plus_operation.to_primitive()) plus_operations.append(plus_operation) if operation_id not in plus_op_required_args: diff --git a/src/aaz_dev/command/model/configuration/_arg_builder.py b/src/aaz_dev/command/model/configuration/_arg_builder.py index cd2aaf2a..e20e592d 100644 --- a/src/aaz_dev/command/model/configuration/_arg_builder.py +++ b/src/aaz_dev/command/model/configuration/_arg_builder.py @@ -158,8 +158,11 @@ def get_sub_args(self): unwrapped_ref_arg = self._ref_arg.get_unwrapped() assert unwrapped_ref_arg is not None sub_ref_args = unwrapped_ref_arg.args - else: + # sometime this will happen for example convert from string arg or any type arg to object arg + elif hasattr(self._ref_arg, 'args'): sub_ref_args = self._ref_arg.args + else: + sub_ref_args = self._sub_ref_args else: sub_ref_args = self._sub_ref_args @@ -250,7 +253,7 @@ def get_any_type(self): def get_additional_props(self): if hasattr(self.schema, "additional_props") and self.schema.additional_props: - sub_ref_arg = self._ref_arg.additional_props if self._ref_arg else None + sub_ref_arg = self._ref_arg.additional_props if self._ref_arg and hasattr(self._ref_arg, 'additional_props') else None sub_builder = self.get_sub_builder(schema=self.schema.additional_props, ref_arg=sub_ref_arg) return sub_builder._build_arg_base() else: From 4c6409d9283bd1afb719fd563989fe1e25e63b5b Mon Sep 17 00:00:00 2001 From: kai ru Date: Tue, 4 Mar 2025 13:32:16 +0800 Subject: [PATCH 2/2] save --- src/aaz_dev/command/controller/workspace_cfg_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aaz_dev/command/controller/workspace_cfg_editor.py b/src/aaz_dev/command/controller/workspace_cfg_editor.py index 3cd23f0e..8775a716 100644 --- a/src/aaz_dev/command/controller/workspace_cfg_editor.py +++ b/src/aaz_dev/command/controller/workspace_cfg_editor.py @@ -246,7 +246,7 @@ def merge(self, plus_cfg_editor): plus_operation.http.request.header = operation.http.request.header plus_operation.http.request.body = operation.http.request.body plus_operation.http.responses = operation.http.responses - if operation.http.request.method.lower() == 'get': + if plus_operation.http.request.method.lower() == 'get' and plus_operation.http.request.query.params: # the get method in generate update command will ignore the optional query params if it's not exist in the put or patch operations. # here we need to exclude them if those query params has args in the main command params = []