Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复创建工单时, 工单自动通过时的报错 #2438

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading