Skip to content

Commit

Permalink
bugfix: 修复子流程节点yaml导出后导入报错问题
Browse files Browse the repository at this point in the history
  • Loading branch information
normal-wls committed Sep 9, 2022
1 parent fab053b commit 9684a18
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion gcloud/template_base/apis/django/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from gcloud.utils.strings import string_to_boolean
from gcloud.exceptions import FlowExportError
from gcloud.template_base.utils import read_template_data_file
from gcloud.utils.yaml import NoAliasSafeDumper

logger = logging.getLogger("root")

Expand Down Expand Up @@ -393,7 +394,7 @@ def export_yaml_templates(request: Request):
return JsonResponse(convert_result)

yaml_data = convert_result["data"]
file_data = yaml.dump_all(yaml_data, allow_unicode=True, sort_keys=False)
file_data = yaml.dump_all(yaml_data, allow_unicode=True, sort_keys=False, Dumper=NoAliasSafeDumper)
filename = "bk_sops_%s_%s.yaml" % (project_id or template_type, time_now_str())
response = HttpResponse()
response["Content-Disposition"] = "attachment; filename=%s" % filename
Expand Down
11 changes: 8 additions & 3 deletions gcloud/template_base/domains/schema_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ def _reconvert_nodes_in_tree(self, nodes: dict, reconverted_tree: dict, cur_temp
"outgoing": node.pop("next") if "next" in node else [nodes[i + 1]["id"]],
}
inputs = node.pop("data") if "data" in node else {}
hooked_inputs = {key: value for key, value in inputs.items() if "key" in value}
outputs = node.pop("output") if "output" in node else {}
subprocess.update(node)
constants = dict(
Expand All @@ -272,11 +273,13 @@ def _reconvert_nodes_in_tree(self, nodes: dict, reconverted_tree: dict, cur_temp
)
constants = copy.deepcopy(constants)
for key, constant in constants.items():
if key in inputs:
constant["value"] = inputs[key]["key"]
if key in hooked_inputs:
constant["value"] = hooked_inputs[key]["key"]
elif key in inputs:
constant["value"] = inputs[key]["value"]

subprocess["constants"] = constants
subprocess_constants = {"component_inputs": inputs, "component_outputs": outputs}
subprocess_constants = {"component_inputs": hooked_inputs, "component_outputs": outputs}
for source_type, data in subprocess_constants.items():
for form_key, param in data.items():
source_info = (node["id"], form_key)
Expand Down Expand Up @@ -549,6 +552,8 @@ def _convert_node(self, node: dict, param_constants: dict):
for form_key, constant in param_constants["component_outputs"].get(node["id"], {}).items():
converted_node.setdefault("output", {})[form_key] = constant
elif node["type"] == "SubProcess":
for key, constant in node["constants"].items():
converted_node.setdefault("data", {})[key] = {"value": constant["value"]}
# 处理 对应勾选的constants
for form_key, constant in param_constants["component_inputs"].get(node["id"], {}).items():
converted_node.setdefault("data", {})[form_key] = constant
Expand Down
18 changes: 18 additions & 0 deletions gcloud/utils/yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
"""
Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community
Edition) available.
Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
import yaml


class NoAliasSafeDumper(yaml.SafeDumper):
def ignore_aliases(self, data):
return True

0 comments on commit 9684a18

Please sign in to comment.