diff --git a/dbm-ui/backend/db_services/mysql/remote_service/handlers.py b/dbm-ui/backend/db_services/mysql/remote_service/handlers.py index 3290fdcc7c..41d2351069 100644 --- a/dbm-ui/backend/db_services/mysql/remote_service/handlers.py +++ b/dbm-ui/backend/db_services/mysql/remote_service/handlers.py @@ -8,6 +8,7 @@ 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 copy from collections import defaultdict from typing import Any, Dict, List, Union @@ -29,12 +30,13 @@ def __init__(self, bk_biz_id: int): @classmethod def _format_db_tb_name(cls, _data_names): - for index in range(len(_data_names)): + _copied_data = copy.deepcopy(_data_names) + for index in range(len(_copied_data)): # mysql模糊匹配单个字符,用_,原本字符串里带的_,要\_转义,如果是*,则转为%表示like % --> 永真 - _data_names[index] = ( - _data_names[index].replace("_", "\_").replace("?", "_").replace("*", "%") # noqa: W605 - ) - return _data_names + _copied_data[index] = ( + _copied_data[index].replace("_", "\_").replace("?", "_").replace("*", "%") + ) # noqa: W605 + return _copied_data @classmethod def _get_db_tb_sts(cls, _data_names, key, default): diff --git a/dbm-ui/backend/ticket/handler.py b/dbm-ui/backend/ticket/handler.py index 5e5970d462..010f7f8a14 100644 --- a/dbm-ui/backend/ticket/handler.py +++ b/dbm-ui/backend/ticket/handler.py @@ -370,21 +370,25 @@ def query_ticket_flows_describe(cls, bk_biz_id, db_type, ticket_types=None): ticket_flow_configs = TicketFlowsConfig.objects.filter(config_filter) # 获得单据flow配置映射表和集群映射表 - flow_config_map = {config.ticket_type: config.configs for config in ticket_flow_configs} + biz_config_map = {cfg.ticket_type: cfg.configs for cfg in ticket_flow_configs if not cfg.cluster_ids} + cluster_config_map = {cfg.ticket_type: cfg.configs for cfg in ticket_flow_configs if cfg.cluster_ids} + + # 获得集群映射表 cluster_ids = list(itertools.chain(*ticket_flow_configs.values_list("cluster_ids", flat=True))) clusters_map = {c.id: c for c in Cluster.objects.filter(id__in=cluster_ids)} # 获取单据流程配置信息 flow_desc_list: List[Dict] = [] for flow_config in ticket_flow_configs: - # 获取当前单据的执行流程描述 - flow_desc = BuilderFactory.registry[flow_config.ticket_type].describe_ticket_flows(flow_config_map) # 获取集群的描述 cluster_info = [ - {"cluster_id": clusters_map[c].id, "immute_domain": clusters_map[c].immute_domain} - for c in flow_config.cluster_ids - if c in clusters_map + {"cluster_id": clusters_map[cluster_id].id, "immute_domain": clusters_map[cluster_id].immute_domain} + for cluster_id in flow_config.cluster_ids + if cluster_id in clusters_map ] + # 获取当前单据的执行流程描述 + config_map = cluster_config_map if cluster_info else biz_config_map + flow_desc = BuilderFactory.registry[flow_config.ticket_type].describe_ticket_flows(config_map) # 获取配置的基本信息 flow_config_info = model_to_dict(flow_config) flow_config_info.update(