fix: auto-fix code issues (cron)
- 修复缺失导入: main.py 添加 AttributeTemplate 和 EntityAttribute 导入 - 修复裸异常捕获: 将 BaseException 改为具体异常类型 - neo4j_manager.py: Exception - main.py: json.JSONDecodeError, ValueError, Exception - export_manager.py: AttributeError, TypeError, ValueError - localization_manager.py: ValueError, AttributeError - performance_manager.py: TypeError, ValueError - plugin_manager.py: OSError, IOError - 修复部分行长度问题: security_manager.py 长行拆分
This commit is contained in:
@@ -281,7 +281,7 @@ class ExportManager:
|
||||
try:
|
||||
if len(str(cell.value)) > max_length:
|
||||
max_length = len(str(cell.value))
|
||||
except BaseException:
|
||||
except (AttributeError, TypeError, ValueError):
|
||||
pass
|
||||
adjusted_width = min(max_length + 2, 50)
|
||||
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||
|
||||
@@ -1337,7 +1337,7 @@ class LocalizationManager:
|
||||
return dates.format_time(dt, locale=locale)
|
||||
else:
|
||||
return dates.format_datetime(dt, locale=locale)
|
||||
except BaseException:
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
return dt.strftime(fmt)
|
||||
except Exception as e:
|
||||
@@ -1354,7 +1354,7 @@ class LocalizationManager:
|
||||
return numbers.format_decimal(
|
||||
number, locale=locale, decimal_quantization=(decimal_places is not None)
|
||||
)
|
||||
except BaseException:
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
if decimal_places is not None:
|
||||
return f"{number:,.{decimal_places}f}"
|
||||
@@ -1369,7 +1369,7 @@ class LocalizationManager:
|
||||
try:
|
||||
locale = Locale.parse(language.replace("_", "-"))
|
||||
return numbers.format_currency(amount, currency, locale=locale)
|
||||
except BaseException:
|
||||
except (ValueError, AttributeError):
|
||||
pass
|
||||
return f"{currency} {amount:,.2f}"
|
||||
except Exception as e:
|
||||
|
||||
@@ -59,7 +59,13 @@ except ImportError:
|
||||
TINGWU_AVAILABLE = False
|
||||
|
||||
try:
|
||||
from db_manager import Entity, EntityMention, get_db_manager
|
||||
from db_manager import (
|
||||
AttributeTemplate,
|
||||
Entity,
|
||||
EntityAttribute,
|
||||
EntityMention,
|
||||
get_db_manager,
|
||||
)
|
||||
|
||||
DB_AVAILABLE = True
|
||||
except ImportError as e:
|
||||
@@ -2016,7 +2022,7 @@ async def agent_suggest(project_id: str, _=Depends(verify_api_key)):
|
||||
try:
|
||||
data = json.loads(json_match.group())
|
||||
return data
|
||||
except BaseException:
|
||||
except (json.JSONDecodeError, ValueError):
|
||||
pass
|
||||
|
||||
return {"suggestions": []}
|
||||
@@ -3060,7 +3066,7 @@ async def export_report_pdf_endpoint(project_id: str, _=Depends(verify_api_key))
|
||||
reasoner = get_knowledge_reasoner()
|
||||
summary_result = reasoner.generate_project_summary(project_id, db)
|
||||
summary = summary_result.get("summary", "")
|
||||
except BaseException:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
export_mgr = get_export_manager()
|
||||
|
||||
@@ -134,7 +134,7 @@ class Neo4jManager:
|
||||
try:
|
||||
self._driver.verify_connectivity()
|
||||
return True
|
||||
except BaseException:
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def init_schema(self) -> None:
|
||||
|
||||
@@ -234,7 +234,7 @@ class CacheManager:
|
||||
"""估算缓存条目大小"""
|
||||
try:
|
||||
return len(json.dumps(value, ensure_ascii=False).encode("utf-8"))
|
||||
except BaseException:
|
||||
except (TypeError, ValueError):
|
||||
return 1024 # 默认估算
|
||||
|
||||
def _evict_lru(self, required_space: int = 0) -> None:
|
||||
|
||||
@@ -1337,7 +1337,7 @@ class WebDAVSyncManager:
|
||||
remote_project_path = f"{sync.remote_path}/{sync.project_id}"
|
||||
try:
|
||||
client.mkdir(remote_project_path)
|
||||
except BaseException:
|
||||
except (OSError, IOError):
|
||||
pass # 目录可能已存在
|
||||
|
||||
# 获取项目数据
|
||||
|
||||
@@ -297,9 +297,12 @@ class SecurityManager:
|
||||
""")
|
||||
|
||||
# 创建索引
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_audit_logs_user ON audit_logs(user_id)")
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_audit_logs_resource ON audit_logs(resource_type, resource_id)"
|
||||
"CREATE INDEX IF NOT EXISTS idx_audit_logs_user ON audit_logs(user_id)"
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_audit_logs_resource "
|
||||
"ON audit_logs(resource_type, resource_id)"
|
||||
)
|
||||
cursor.execute(
|
||||
"CREATE INDEX IF NOT EXISTS idx_audit_logs_action ON audit_logs(action_type)"
|
||||
|
||||
Reference in New Issue
Block a user