fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题 (816+ 处)
- 添加缺失的导入 (json, re)
- 统一SQL查询格式
- 修复赋值语句空格问题

修复文件:
- db_manager.py (96处)
- search_manager.py (77处)
- ops_manager.py (66处)
- developer_ecosystem_manager.py (68处)
- growth_manager.py (60处)
- enterprise_manager.py (61处)
- tenant_manager.py (57处)
- plugin_manager.py (48处)
- subscription_manager.py (46处)
- security_manager.py (29处)
- workflow_manager.py (32处)
- localization_manager.py (31处)
- api_key_manager.py (20处)
- ai_manager.py (23处)
- performance_manager.py (24处)
- neo4j_manager.py (25处)
- collaboration_manager.py (33处)
- test_phase8_task8.py (16处)
- test_phase8_task6.py (4处)
- knowledge_reasoner.py (添加import json)
- llm_client.py (添加import json)
This commit is contained in:
AutoFix Bot
2026-03-03 00:11:51 +08:00
parent c695e99eaf
commit 2a0ed6af4d
23 changed files with 1160 additions and 947 deletions

View File

@@ -212,7 +212,7 @@ class PluginManager:
def get_plugin(self, plugin_id: str) -> Plugin | None:
"""获取插件"""
conn = self.db.get_conn()
row = conn.execute("SELECT * FROM plugins WHERE id = ?", (plugin_id,)).fetchone()
row = conn.execute("SELECT * FROM plugins WHERE id = ?", (plugin_id,)).fetchone()
conn.close()
if row:
@@ -229,13 +229,13 @@ class PluginManager:
params = []
if project_id:
conditions.append("project_id = ?")
conditions.append("project_id = ?")
params.append(project_id)
if plugin_type:
conditions.append("plugin_type = ?")
conditions.append("plugin_type = ?")
params.append(plugin_type)
if status:
conditions.append("status = ?")
conditions.append("status = ?")
params.append(status)
where_clause = " AND ".join(conditions) if conditions else "1 = 1"
@@ -267,11 +267,11 @@ class PluginManager:
conn.close()
return self.get_plugin(plugin_id)
updates.append("updated_at = ?")
updates.append("updated_at = ?")
values.append(datetime.now().isoformat())
values.append(plugin_id)
query = f"UPDATE plugins SET {', '.join(updates)} WHERE id = ?"
query = f"UPDATE plugins SET {', '.join(updates)} WHERE id = ?"
conn.execute(query, values)
conn.commit()
conn.close()
@@ -283,10 +283,10 @@ class PluginManager:
conn = self.db.get_conn()
# 删除关联的配置
conn.execute("DELETE FROM plugin_configs WHERE plugin_id = ?", (plugin_id,))
conn.execute("DELETE FROM plugin_configs WHERE plugin_id = ?", (plugin_id,))
# 删除插件
cursor = conn.execute("DELETE FROM plugins WHERE id = ?", (plugin_id,))
cursor = conn.execute("DELETE FROM plugins WHERE id = ?", (plugin_id,))
conn.commit()
conn.close()
@@ -318,15 +318,15 @@ class PluginManager:
# 检查是否已存在
existing = conn.execute(
"SELECT id FROM plugin_configs WHERE plugin_id = ? AND config_key = ?",
"SELECT id FROM plugin_configs WHERE plugin_id = ? AND config_key = ?",
(plugin_id, key),
).fetchone()
if existing:
conn.execute(
"""UPDATE plugin_configs
SET config_value = ?, is_encrypted = ?, updated_at = ?
WHERE id = ?""",
SET config_value = ?, is_encrypted = ?, updated_at = ?
WHERE id = ?""",
(value, is_encrypted, now, existing["id"]),
)
config_id = existing["id"]
@@ -356,7 +356,7 @@ class PluginManager:
"""获取插件配置"""
conn = self.db.get_conn()
row = conn.execute(
"SELECT config_value FROM plugin_configs WHERE plugin_id = ? AND config_key = ?",
"SELECT config_value FROM plugin_configs WHERE plugin_id = ? AND config_key = ?",
(plugin_id, key),
).fetchone()
conn.close()
@@ -367,7 +367,7 @@ class PluginManager:
"""获取插件所有配置"""
conn = self.db.get_conn()
rows = conn.execute(
"SELECT config_key, config_value FROM plugin_configs WHERE plugin_id = ?", (plugin_id,)
"SELECT config_key, config_value FROM plugin_configs WHERE plugin_id = ?", (plugin_id,)
).fetchall()
conn.close()
@@ -377,7 +377,7 @@ class PluginManager:
"""删除插件配置"""
conn = self.db.get_conn()
cursor = conn.execute(
"DELETE FROM plugin_configs WHERE plugin_id = ? AND config_key = ?", (plugin_id, key)
"DELETE FROM plugin_configs WHERE plugin_id = ? AND config_key = ?", (plugin_id, key)
)
conn.commit()
conn.close()
@@ -391,8 +391,8 @@ class PluginManager:
conn.execute(
"""UPDATE plugins
SET use_count = use_count + 1, last_used_at = ?
WHERE id = ?""",
SET use_count = use_count + 1, last_used_at = ?
WHERE id = ?""",
(now, plugin_id),
)
conn.commit()
@@ -471,7 +471,7 @@ class ChromeExtensionHandler:
conn = self.pm.db.get_conn()
row = conn.execute(
"""SELECT * FROM chrome_extension_tokens
WHERE token_hash = ? AND is_revoked = 0""",
WHERE token_hash = ? AND is_revoked = 0""",
(token_hash,),
).fetchone()
conn.close()
@@ -488,8 +488,8 @@ class ChromeExtensionHandler:
conn = self.pm.db.get_conn()
conn.execute(
"""UPDATE chrome_extension_tokens
SET use_count = use_count + 1, last_used_at = ?
WHERE id = ?""",
SET use_count = use_count + 1, last_used_at = ?
WHERE id = ?""",
(now, row["id"]),
)
conn.commit()
@@ -512,7 +512,7 @@ class ChromeExtensionHandler:
"""撤销令牌"""
conn = self.pm.db.get_conn()
cursor = conn.execute(
"UPDATE chrome_extension_tokens SET is_revoked = 1 WHERE id = ?", (token_id,)
"UPDATE chrome_extension_tokens SET is_revoked = 1 WHERE id = ?", (token_id,)
)
conn.commit()
conn.close()
@@ -525,14 +525,14 @@ class ChromeExtensionHandler:
"""列出令牌"""
conn = self.pm.db.get_conn()
conditions = ["is_revoked = 0"]
conditions = ["is_revoked = 0"]
params = []
if user_id:
conditions.append("user_id = ?")
conditions.append("user_id = ?")
params.append(user_id)
if project_id:
conditions.append("project_id = ?")
conditions.append("project_id = ?")
params.append(project_id)
where_clause = " AND ".join(conditions)
@@ -665,7 +665,7 @@ class BotHandler:
conn = self.pm.db.get_conn()
row = conn.execute(
"""SELECT * FROM bot_sessions
WHERE session_id = ? AND bot_type = ?""",
WHERE session_id = ? AND bot_type = ?""",
(session_id, self.bot_type),
).fetchone()
conn.close()
@@ -681,13 +681,13 @@ class BotHandler:
if project_id:
rows = conn.execute(
"""SELECT * FROM bot_sessions
WHERE bot_type = ? AND project_id = ? ORDER BY created_at DESC""",
WHERE bot_type = ? AND project_id = ? ORDER BY created_at DESC""",
(self.bot_type, project_id),
).fetchall()
else:
rows = conn.execute(
"""SELECT * FROM bot_sessions
WHERE bot_type = ? ORDER BY created_at DESC""",
WHERE bot_type = ? ORDER BY created_at DESC""",
(self.bot_type,),
).fetchall()
@@ -712,13 +712,13 @@ class BotHandler:
conn.close()
return self.get_session(session_id)
updates.append("updated_at = ?")
updates.append("updated_at = ?")
values.append(datetime.now().isoformat())
values.append(session_id)
values.append(self.bot_type)
query = (
f"UPDATE bot_sessions SET {', '.join(updates)} WHERE session_id = ? AND bot_type = ?"
f"UPDATE bot_sessions SET {', '.join(updates)} WHERE session_id = ? AND bot_type = ?"
)
conn.execute(query, values)
conn.commit()
@@ -730,7 +730,7 @@ class BotHandler:
"""删除会话"""
conn = self.pm.db.get_conn()
cursor = conn.execute(
"DELETE FROM bot_sessions WHERE session_id = ? AND bot_type = ?",
"DELETE FROM bot_sessions WHERE session_id = ? AND bot_type = ?",
(session_id, self.bot_type),
)
conn.commit()
@@ -763,8 +763,8 @@ class BotHandler:
conn = self.pm.db.get_conn()
conn.execute(
"""UPDATE bot_sessions
SET message_count = message_count + 1, last_message_at = ?
WHERE id = ?""",
SET message_count = message_count + 1, last_message_at = ?
WHERE id = ?""",
(now, session.id),
)
conn.commit()
@@ -995,7 +995,7 @@ class WebhookIntegration:
"""获取端点"""
conn = self.pm.db.get_conn()
row = conn.execute(
"SELECT * FROM webhook_endpoints WHERE id = ? AND endpoint_type = ?",
"SELECT * FROM webhook_endpoints WHERE id = ? AND endpoint_type = ?",
(endpoint_id, self.endpoint_type),
).fetchone()
conn.close()
@@ -1011,13 +1011,13 @@ class WebhookIntegration:
if project_id:
rows = conn.execute(
"""SELECT * FROM webhook_endpoints
WHERE endpoint_type = ? AND project_id = ? ORDER BY created_at DESC""",
WHERE endpoint_type = ? AND project_id = ? ORDER BY created_at DESC""",
(self.endpoint_type, project_id),
).fetchall()
else:
rows = conn.execute(
"""SELECT * FROM webhook_endpoints
WHERE endpoint_type = ? ORDER BY created_at DESC""",
WHERE endpoint_type = ? ORDER BY created_at DESC""",
(self.endpoint_type,),
).fetchall()
@@ -1053,11 +1053,11 @@ class WebhookIntegration:
conn.close()
return self.get_endpoint(endpoint_id)
updates.append("updated_at = ?")
updates.append("updated_at = ?")
values.append(datetime.now().isoformat())
values.append(endpoint_id)
query = f"UPDATE webhook_endpoints SET {', '.join(updates)} WHERE id = ?"
query = f"UPDATE webhook_endpoints SET {', '.join(updates)} WHERE id = ?"
conn.execute(query, values)
conn.commit()
conn.close()
@@ -1067,7 +1067,7 @@ class WebhookIntegration:
def delete_endpoint(self, endpoint_id: str) -> bool:
"""删除端点"""
conn = self.pm.db.get_conn()
cursor = conn.execute("DELETE FROM webhook_endpoints WHERE id = ?", (endpoint_id,))
cursor = conn.execute("DELETE FROM webhook_endpoints WHERE id = ?", (endpoint_id,))
conn.commit()
conn.close()
@@ -1125,8 +1125,8 @@ class WebhookIntegration:
conn = self.pm.db.get_conn()
conn.execute(
"""UPDATE webhook_endpoints
SET trigger_count = trigger_count + 1, last_triggered_at = ?
WHERE id = ?""",
SET trigger_count = trigger_count + 1, last_triggered_at = ?
WHERE id = ?""",
(now, endpoint.id),
)
conn.commit()
@@ -1222,7 +1222,7 @@ class WebDAVSyncManager:
def get_sync(self, sync_id: str) -> WebDAVSync | None:
"""获取同步配置"""
conn = self.pm.db.get_conn()
row = conn.execute("SELECT * FROM webdav_syncs WHERE id = ?", (sync_id,)).fetchone()
row = conn.execute("SELECT * FROM webdav_syncs WHERE id = ?", (sync_id,)).fetchone()
conn.close()
if row:
@@ -1235,7 +1235,7 @@ class WebDAVSyncManager:
if project_id:
rows = conn.execute(
"SELECT * FROM webdav_syncs WHERE project_id = ? ORDER BY created_at DESC",
"SELECT * FROM webdav_syncs WHERE project_id = ? ORDER BY created_at DESC",
(project_id,),
).fetchall()
else:
@@ -1271,11 +1271,11 @@ class WebDAVSyncManager:
conn.close()
return self.get_sync(sync_id)
updates.append("updated_at = ?")
updates.append("updated_at = ?")
values.append(datetime.now().isoformat())
values.append(sync_id)
query = f"UPDATE webdav_syncs SET {', '.join(updates)} WHERE id = ?"
query = f"UPDATE webdav_syncs SET {', '.join(updates)} WHERE id = ?"
conn.execute(query, values)
conn.commit()
conn.close()
@@ -1285,7 +1285,7 @@ class WebDAVSyncManager:
def delete_sync(self, sync_id: str) -> bool:
"""删除同步配置"""
conn = self.pm.db.get_conn()
cursor = conn.execute("DELETE FROM webdav_syncs WHERE id = ?", (sync_id,))
cursor = conn.execute("DELETE FROM webdav_syncs WHERE id = ?", (sync_id,))
conn.commit()
conn.close()
@@ -1387,8 +1387,8 @@ class WebDAVSyncManager:
conn = self.pm.db.get_conn()
conn.execute(
"""UPDATE webdav_syncs
SET last_sync_at = ?, last_sync_status = ?, sync_count = sync_count + 1
WHERE id = ?""",
SET last_sync_at = ?, last_sync_status = ?, sync_count = sync_count + 1
WHERE id = ?""",
(now, "success", sync.id),
)
conn.commit()
@@ -1407,8 +1407,8 @@ class WebDAVSyncManager:
conn = self.pm.db.get_conn()
conn.execute(
"""UPDATE webdav_syncs
SET last_sync_status = ?, last_sync_error = ?
WHERE id = ?""",
SET last_sync_status = ?, last_sync_error = ?
WHERE id = ?""",
("failed", str(e), sync.id),
)
conn.commit()