Skip to content

Commit

Permalink
修复创建工单时, 工单自动通过时的报错 (#2438)
Browse files Browse the repository at this point in the history
* 修复创建工单时, 工单自动通过时的报错

* b
  • Loading branch information
LeoQuote authored Dec 4, 2023
1 parent 216732a commit 86b217d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
15 changes: 13 additions & 2 deletions sql/utils/workflow_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def is_auto_review(self) -> bool:

def generate_audit_setting(self) -> AuditSetting:
if self.is_auto_review():
return AuditSetting(auto_pass=True, audit_auth_groups=["无需审批"])
return AuditSetting(auto_pass=True)
if self.workflow_type in [WorkflowType.SQL_REVIEW, WorkflowType.QUERY]:
group_id = self.workflow.group_id

Expand Down Expand Up @@ -540,7 +540,18 @@ def get_review_info(self) -> ReviewInfo:
)
)
continue
g = int(g)
try:
g = int(g)
except ValueError: # pragma: no cover
# 脏数据, 当成自动通过
# 兼容代码, 一般是空值代表自动通过
review_nodes.append(
ReviewNode(
node_type=ReviewNodeType.AUTO_PASS,
is_passed_node=True,
)
)
continue
group_in_db = Group.objects.get(id=g)
if self.audit.current_status != WorkflowStatus.WAITING:
# 总体状态不是待审核, 不设置详细的属性
Expand Down
6 changes: 3 additions & 3 deletions sql/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
AuditEntry,
TwoFactorAuthConfig,
)
from sql.utils.workflow_audit import Audit, AuditV2, AuditException, ReviewNodeType
from sql.utils.workflow_audit import Audit, AuditV2, AuditException
from sql.utils.sql_review import (
can_execute,
can_timingtask,
Expand All @@ -40,7 +40,7 @@
can_rollback,
)
from common.utils.const import Const, WorkflowType, WorkflowAction
from sql.utils.resource_group import user_groups, user_instances, auth_group_users
from sql.utils.resource_group import user_groups, user_instances

import logging

Expand Down Expand Up @@ -501,7 +501,7 @@ def config(request):
# 获取所有实例标签
instance_tags = InstanceTag.objects.all()
# 支持自动审核的数据库类型
db_type = ["mysql", "oracle", "mongo", "clickhouse"]
db_type = ["mysql", "oracle", "mongo", "clickhouse", "redis"]
# 获取所有配置项
all_config = Config.objects.all().values("item", "value")
sys_config = {}
Expand Down
7 changes: 4 additions & 3 deletions sql_api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,13 @@ def create(self, validated_data):
with transaction.atomic():
workflow = SqlWorkflow(**workflow_data)
validated_data["review_content"] = check_result.json()
# 自动创建工作流
auditor = get_auditor(workflow=workflow)
auditor.create_audit()
workflow.save()
workflow_content = SqlWorkflowContent.objects.create(
workflow=workflow, **validated_data
)
# 自动创建工作流
auditor = get_auditor(workflow=workflow)
auditor.create_audit()
except Exception as e:
logger.error(f"提交工单报错,错误信息:{traceback.format_exc()}")
raise serializers.ValidationError({"errors": str(e)})
Expand Down

0 comments on commit 86b217d

Please sign in to comment.