From 4c12301e81c4cd19e0e86baaf0c00ce62bceb746 Mon Sep 17 00:00:00 2001 From: BukeLy Date: Wed, 19 Nov 2025 23:31:09 +0800 Subject: [PATCH] fix: correct parameter passing in delete_entity_relation Why this change is needed: The previous fix in commit 7dc1f83e incorrectly "fixed" delete_entity_relation by converting the parameter dict to a list. However, PostgreSQLDB.execute() expects a dict[str, Any] parameter, not a list. The execute() method internally converts dict values to tuple (line 1487: tuple(data.values())), so passing a list bypasses the expected interface and causes parameter binding issues. What was wrong: ```python params = {"workspace": self.workspace, "entity_name": entity_name} await self.db.execute(delete_sql, list(params.values())) # WRONG ``` The correct approach (matching delete_entity method): ```python await self.db.execute( delete_sql, {"workspace": self.workspace, "entity_name": entity_name} ) ``` How it solves it: - Pass parameters as a dict directly to db.execute(), matching the method signature - Maintain consistency with delete_entity() which correctly passes a dict - Let db.execute() handle the dict-to-tuple conversion internally as designed Impact: - delete_entity_relation now correctly passes parameters to PostgreSQL - Method interface consistency with other delete operations - Proper parameter binding ensures reliable entity relation deletion Testing: - All 6 PostgreSQL migration tests pass - Verified parameter passing matches delete_entity pattern - Code review identified the issue before production use Related: - Fixes incorrect "fix" from commit 7dc1f83e - Aligns with PostgreSQLDB.execute() interface (line 1477-1480) --- lightrag/kg/postgres_impl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lightrag/kg/postgres_impl.py b/lightrag/kg/postgres_impl.py index a17dcfe3..f0d2329c 100644 --- a/lightrag/kg/postgres_impl.py +++ b/lightrag/kg/postgres_impl.py @@ -2604,8 +2604,9 @@ class PGVectorStorage(BaseVectorStorage): delete_sql = f"""DELETE FROM {self.table_name} WHERE workspace=$1 AND (source_id=$2 OR target_id=$2)""" - params = {"workspace": self.workspace, "entity_name": entity_name} - await self.db.execute(delete_sql, list(params.values())) + await self.db.execute( + delete_sql, {"workspace": self.workspace, "entity_name": entity_name} + ) logger.debug( f"[{self.workspace}] Successfully deleted relations for entity {entity_name}" )