Hot Fix AttributeError in Neo4JStorage and MemgraphStorage when using storage specified workspace env var#2526
Merged
danielaskdd merged 1 commit intoHKUDS:mainfrom Dec 23, 2025
Conversation
- Move override logging after super init - Fix access to uninitialized attributes - Store original workspace for logs - Update Memgraph implementation - Update Neo4j implementation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hot Fix AttributeError in Neo4JStorage and MemgraphStorage when using storage specified workspace env var
Summary
This PR fixes a critical bug in
Neo4JStorageandMemgraphStoragethat causes anAttributeErrorwhen theNEO4J_WORKSPACEorMEMGRAPH_WORKSPACEenvironment variables are set.Problem
When initializing LightRAG with Neo4J or Memgraph graph storage and the workspace environment variable is set, the application crashes with:
or
Root Cause
Both
Neo4JStorageandMemgraphStorageuse custom__init__methods that attempt to accessself.workspaceandself.namespaceattributes before callingsuper().__init__(). Since these attributes are defined in the parentBaseGraphStoragedataclass and initialized by the parent's__init__, they don't exist untilsuper().__init__()is called.The problematic code pattern was:
Solution
Move the logging statement to after
super().__init__()is called, and use parameter values instead ofselfattributes in the log message:Changes
lightrag/kg/neo4j_impl.py: FixedNeo4JStorage.__init__()to access attributes only after parent initializationlightrag/kg/memgraph_impl.py: FixedMemgraphStorage.__init__()to access attributes only after parent initializationWhy Other Storage Implementations Are Not Affected
Other storage implementations (Redis, Milvus, PostgreSQL, MongoDB, Qdrant, etc.) use dataclass
__post_init__methods instead of custom__init__methods. With__post_init__, the dataclass framework automatically initializes all fields (includingworkspaceandnamespace) before__post_init__is called, so there is no issue.Testing
NEO4J_WORKSPACEenvironment variableAttributeErroris raisedBreaking Changes
None. This is a pure bug fix with no API changes.
Related Issues
Fixes the error: