fix linting

This commit is contained in:
zrguo
2025-03-04 16:12:27 +08:00
parent 4ebaf8026b
commit 1ee6c23a53

View File

@@ -739,57 +739,59 @@ class OracleGraphStorage(BaseGraphStorage):
async def remove_nodes(self, nodes: list[str]) -> None: async def remove_nodes(self, nodes: list[str]) -> None:
"""Delete multiple nodes from the graph """Delete multiple nodes from the graph
Args: Args:
nodes: List of node IDs to be deleted nodes: List of node IDs to be deleted
""" """
if not nodes: if not nodes:
return return
try: try:
for node in nodes: for node in nodes:
# For each node, first delete all its relationships # For each node, first delete all its relationships
delete_relations_sql = SQL_TEMPLATES["delete_entity_relations"] delete_relations_sql = SQL_TEMPLATES["delete_entity_relations"]
params_relations = {"workspace": self.db.workspace, "entity_name": node} params_relations = {"workspace": self.db.workspace, "entity_name": node}
await self.db.execute(delete_relations_sql, params_relations) await self.db.execute(delete_relations_sql, params_relations)
# Then delete the node itself # Then delete the node itself
delete_node_sql = SQL_TEMPLATES["delete_entity"] delete_node_sql = SQL_TEMPLATES["delete_entity"]
params_node = {"workspace": self.db.workspace, "entity_name": node} params_node = {"workspace": self.db.workspace, "entity_name": node}
await self.db.execute(delete_node_sql, params_node) await self.db.execute(delete_node_sql, params_node)
logger.info(f"Successfully deleted {len(nodes)} nodes and their relationships") logger.info(
f"Successfully deleted {len(nodes)} nodes and their relationships"
)
except Exception as e: except Exception as e:
logger.error(f"Error during batch node deletion: {e}") logger.error(f"Error during batch node deletion: {e}")
raise raise
async def remove_edges(self, edges: list[tuple[str, str]]) -> None: async def remove_edges(self, edges: list[tuple[str, str]]) -> None:
"""Delete multiple edges from the graph """Delete multiple edges from the graph
Args: Args:
edges: List of edges to be deleted, each edge is a (source, target) tuple edges: List of edges to be deleted, each edge is a (source, target) tuple
""" """
if not edges: if not edges:
return return
try: try:
for source, target in edges: for source, target in edges:
# Check if the edge exists before attempting to delete # Check if the edge exists before attempting to delete
if await self.has_edge(source, target): if await self.has_edge(source, target):
# Delete the edge using a SQL query that matches both source and target # Delete the edge using a SQL query that matches both source and target
delete_edge_sql = """ delete_edge_sql = """
DELETE FROM LIGHTRAG_GRAPH_EDGES DELETE FROM LIGHTRAG_GRAPH_EDGES
WHERE workspace = :workspace WHERE workspace = :workspace
AND source_name = :source_name AND source_name = :source_name
AND target_name = :target_name AND target_name = :target_name
""" """
params = { params = {
"workspace": self.db.workspace, "workspace": self.db.workspace,
"source_name": source, "source_name": source,
"target_name": target "target_name": target,
} }
await self.db.execute(delete_edge_sql, params) await self.db.execute(delete_edge_sql, params)
logger.info(f"Successfully deleted {len(edges)} edges from the graph") logger.info(f"Successfully deleted {len(edges)} edges from the graph")
except Exception as e: except Exception as e:
logger.error(f"Error during batch edge deletion: {e}") logger.error(f"Error during batch edge deletion: {e}")