fix ruff lint

This commit is contained in:
youhuanghe
2026-03-09 01:26:39 +00:00
parent f0093dab69
commit 14ea8ca7b6
2 changed files with 9 additions and 21 deletions
@@ -47,9 +47,9 @@ class KnowledgeMigrationRouterGroup(group.RouterGroup):
return result.scalar() return result.scalar()
else: else:
result = await self.ap.persistence_mgr.execute_async( result = await self.ap.persistence_mgr.execute_async(
sqlalchemy.text( sqlalchemy.text("SELECT name FROM sqlite_master WHERE type='table' AND name=:table_name;").bindparams(
"SELECT name FROM sqlite_master WHERE type='table' AND name=:table_name;" table_name=table_name
).bindparams(table_name=table_name) )
) )
return result.first() is not None return result.first() is not None
@@ -231,9 +231,7 @@ class KnowledgeMigrationRouterGroup(group.RouterGroup):
) )
try: try:
await self.ap.plugin_connector.rag_on_kb_create( await self.ap.plugin_connector.rag_on_kb_create(external_plugin_id, kb_uuid, retriever_config)
external_plugin_id, kb_uuid, retriever_config
)
task_context.trace(f'Restored external KB: {name} ({kb_uuid})') task_context.trace(f'Restored external KB: {name} ({kb_uuid})')
except Exception as e: except Exception as e:
warning = f'Failed to notify plugin for external KB {name} ({kb_uuid}): {e}' warning = f'Failed to notify plugin for external KB {name} ({kb_uuid}): {e}'
@@ -59,18 +59,14 @@ class DBMigrateKnowledgeEnginePluginArchitecture(migration.DBMigration):
async def _backup_knowledge_bases(self) -> bool: async def _backup_knowledge_bases(self) -> bool:
"""Backup knowledge_bases data. Returns True if data was backed up.""" """Backup knowledge_bases data. Returns True if data was backed up."""
result = await self.ap.persistence_mgr.execute_async( result = await self.ap.persistence_mgr.execute_async(sqlalchemy.text('SELECT COUNT(*) FROM knowledge_bases;'))
sqlalchemy.text('SELECT COUNT(*) FROM knowledge_bases;')
)
count = result.scalar() count = result.scalar()
if count == 0: if count == 0:
return False return False
# Drop backup table if it already exists (from a previous failed migration) # Drop backup table if it already exists (from a previous failed migration)
if await self._table_exists('knowledge_bases_backup'): if await self._table_exists('knowledge_bases_backup'):
await self.ap.persistence_mgr.execute_async( await self.ap.persistence_mgr.execute_async(sqlalchemy.text('DROP TABLE knowledge_bases_backup;'))
sqlalchemy.text('DROP TABLE knowledge_bases_backup;')
)
await self.ap.persistence_mgr.execute_async( await self.ap.persistence_mgr.execute_async(
sqlalchemy.text('CREATE TABLE knowledge_bases_backup AS SELECT * FROM knowledge_bases;') sqlalchemy.text('CREATE TABLE knowledge_bases_backup AS SELECT * FROM knowledge_bases;')
@@ -103,9 +99,7 @@ class DBMigrateKnowledgeEnginePluginArchitecture(migration.DBMigration):
async def _clear_knowledge_bases(self): async def _clear_knowledge_bases(self):
"""Clear all rows from knowledge_bases table (preserve table structure).""" """Clear all rows from knowledge_bases table (preserve table structure)."""
await self.ap.persistence_mgr.execute_async( await self.ap.persistence_mgr.execute_async(sqlalchemy.text('DELETE FROM knowledge_bases;'))
sqlalchemy.text('DELETE FROM knowledge_bases;')
)
async def _add_columns_to_knowledge_bases(self): async def _add_columns_to_knowledge_bases(self):
"""Add new RAG plugin architecture columns to knowledge_bases table.""" """Add new RAG plugin architecture columns to knowledge_bases table."""
@@ -154,15 +148,11 @@ class DBMigrateKnowledgeEnginePluginArchitecture(migration.DBMigration):
row = result.first() row = result.first()
if row is not None: if row is not None:
await self.ap.persistence_mgr.execute_async( await self.ap.persistence_mgr.execute_async(
sqlalchemy.text( sqlalchemy.text("UPDATE metadata SET value = 'true' WHERE key = 'rag_plugin_migration_needed';")
"UPDATE metadata SET value = 'true' WHERE key = 'rag_plugin_migration_needed';"
)
) )
else: else:
await self.ap.persistence_mgr.execute_async( await self.ap.persistence_mgr.execute_async(
sqlalchemy.text( sqlalchemy.text("INSERT INTO metadata (key, value) VALUES ('rag_plugin_migration_needed', 'true');")
"INSERT INTO metadata (key, value) VALUES ('rag_plugin_migration_needed', 'true');"
)
) )
self.ap.logger.info('Set rag_plugin_migration_needed=true in metadata.') self.ap.logger.info('Set rag_plugin_migration_needed=true in metadata.')