From 51d7ded961a7ead0ff217b027e8f54ebceb016d1 Mon Sep 17 00:00:00 2001 From: Ethan-Zhang Date: Thu, 6 Nov 2025 11:24:52 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E5=88=9D=E5=A7=8B=E5=8C=96=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E6=80=A7=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_chain/apps/app.py | 19 +++++++++++++++++++ data_chain/apps/service/team_service.py | 1 - data_chain/manager/role_manager.py | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/data_chain/apps/app.py b/data_chain/apps/app.py index f8cd6fa..4d9f7f6 100644 --- a/data_chain/apps/app.py +++ b/data_chain/apps/app.py @@ -1,4 +1,8 @@ # Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. +import warnings +# 过滤 APScheduler 中 pkg_resources 弃用警告 +warnings.filterwarnings('ignore', message='pkg_resources is deprecated', category=UserWarning) + from typing import Annotated from fastapi import APIRouter, Depends, Query, Body, HTTPException from fastapi.exceptions import RequestValidationError @@ -136,6 +140,11 @@ async def startup_event(): async def add_acitons(): for action in actions: + # 先检查action是否已存在,避免重复插入 + existing_action = await RoleManager.get_action_by_action(action['action']) + if existing_action: + continue + action_entity = ActionEntity( action=action['action'], name=action['name'][LanguageType.CHINESE], @@ -145,6 +154,11 @@ async def add_acitons(): async def add_knowledge_base(): + # 先检查知识库是否已存在,避免重复插入 + existing_kb = await KnowledgeBaseManager.get_knowledge_base_by_kb_id(DEFAULT_DOC_TYPE_ID) + if existing_kb: + return + knowledge_base_entity = KnowledgeBaseEntity( id=DEFAULT_DOC_TYPE_ID, default_parse_method=ParseMethod.OCR.value @@ -153,6 +167,11 @@ async def add_knowledge_base(): async def add_document_type(): + # 先检查文档类型是否已存在,避免重复插入 + existing_doc_type = await DocumentTypeManager.get_document_type_by_id(DEFAULT_DOC_TYPE_ID) + if existing_doc_type: + return + document_type_entity = DocumentTypeEntity( id=DEFAULT_DOC_TYPE_ID, name="default", diff --git a/data_chain/apps/service/team_service.py b/data_chain/apps/service/team_service.py index 7ee4671..cdb2e02 100644 --- a/data_chain/apps/service/team_service.py +++ b/data_chain/apps/service/team_service.py @@ -87,7 +87,6 @@ class TeamService: team_entites_myjoined = await TeamManager.list_team_myjoined_by_user_sub_and_team_ids(user_sub, team_ids) team_ids_myjoined = [ team_entity.id for team_entity in team_entites_myjoined] - logging.error(team_ids_myjoined) team_entities_mycreated = await TeamManager.list_team_mycreated_by_user_sub_and_team_ids(user_sub, team_ids) team_ids_mycreated = [ team_entity.id for team_entity in team_entities_mycreated] diff --git a/data_chain/manager/role_manager.py b/data_chain/manager/role_manager.py index 26bb556..dd7b7ac 100644 --- a/data_chain/manager/role_manager.py +++ b/data_chain/manager/role_manager.py @@ -93,6 +93,20 @@ class RoleManager: logging.exception("[RoleManager] %s", err) raise e + @staticmethod + async def get_action_by_action(action: str) -> ActionEntity: + """根据action获取操作""" + try: + async with await DataBase.get_session() as session: + stmt = select(ActionEntity).where(ActionEntity.action == action) + result = await session.execute(stmt) + action_entity = result.scalars().first() + return action_entity + except Exception as e: + err = "根据action获取操作失败" + logging.warning("[RoleManager] %s: %s", err, e) + return None + @staticmethod async def get_user_role_by_user_sub_and_team_id( user_sub: str, team_id: uuid.UUID) -> UserRoleEntity: -- Gitee