diff --git a/backend/export_manager.py b/backend/export_manager.py index cdcf9e3..35e7792 100644 --- a/backend/export_manager.py +++ b/backend/export_manager.py @@ -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 diff --git a/backend/localization_manager.py b/backend/localization_manager.py index 2d42b07..6325c31 100644 --- a/backend/localization_manager.py +++ b/backend/localization_manager.py @@ -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: diff --git a/backend/main.py b/backend/main.py index f3e6160..8c65027 100644 --- a/backend/main.py +++ b/backend/main.py @@ -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() diff --git a/backend/neo4j_manager.py b/backend/neo4j_manager.py index c79bfdc..409ccd3 100644 --- a/backend/neo4j_manager.py +++ b/backend/neo4j_manager.py @@ -134,7 +134,7 @@ class Neo4jManager: try: self._driver.verify_connectivity() return True - except BaseException: + except Exception: return False def init_schema(self) -> None: diff --git a/backend/performance_manager.py b/backend/performance_manager.py index 3fe9e82..0b98a8e 100644 --- a/backend/performance_manager.py +++ b/backend/performance_manager.py @@ -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: diff --git a/backend/plugin_manager.py b/backend/plugin_manager.py index 4933edb..e0d74c2 100644 --- a/backend/plugin_manager.py +++ b/backend/plugin_manager.py @@ -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 # 目录可能已存在 # 获取项目数据 diff --git a/backend/security_manager.py b/backend/security_manager.py index d916a25..0fedb52 100644 --- a/backend/security_manager.py +++ b/backend/security_manager.py @@ -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)"