From e5e16b7bd171848c5b973a24eda53ae636ffea31 Mon Sep 17 00:00:00 2001 From: yangdx Date: Tue, 21 Oct 2025 16:27:04 +0800 Subject: [PATCH] Fix Redis data migration error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Use proper Redis connection context • Fix namespace pattern for key scanning • Propagate storage check exceptions • Remove defensive error swallowing --- lightrag/kg/redis_impl.py | 11 ++++++----- lightrag/lightrag.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lightrag/kg/redis_impl.py b/lightrag/kg/redis_impl.py index 8a393497..2e9a7d43 100644 --- a/lightrag/kg/redis_impl.py +++ b/lightrag/kg/redis_impl.py @@ -368,12 +368,13 @@ class RedisKVStorage(BaseKVStorage): Returns: bool: True if storage is empty, False otherwise """ - pattern = f"{self.namespace}:{self.workspace}:*" + pattern = f"{self.final_namespace}:*" try: - # Use scan to check if any keys exist - async for key in self.redis.scan_iter(match=pattern, count=1): - return False # Found at least one key - return True # No keys found + async with self._get_redis_connection() as redis: + # Use scan to check if any keys exist + async for key in redis.scan_iter(match=pattern, count=1): + return False # Found at least one key + return True # No keys found except Exception as e: logger.error(f"[{self.workspace}] Error checking if storage is empty: {e}") return True diff --git a/lightrag/lightrag.py b/lightrag/lightrag.py index 4380a276..afd1de76 100644 --- a/lightrag/lightrag.py +++ b/lightrag/lightrag.py @@ -887,13 +887,13 @@ class LightRAG: need_entity_migration = await self.entity_chunks.is_empty() except Exception as exc: # pragma: no cover - defensive logging logger.error(f"Failed to check entity chunks storage: {exc}") - need_entity_migration = True + raise exc try: need_relation_migration = await self.relation_chunks.is_empty() except Exception as exc: # pragma: no cover - defensive logging logger.error(f"Failed to check relation chunks storage: {exc}") - need_relation_migration = True + raise exc if not need_entity_migration and not need_relation_migration: return