From eed44e676108de35fc49b677949e1a65116b508e Mon Sep 17 00:00:00 2001 From: Cameron Pfiffer Date: Tue, 27 May 2025 20:32:27 -0700 Subject: [PATCH] fix: Resolve circular import between record_manager and graph_sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add multiple import path fallbacks in record_manager._initialize_graph_sync() - Remove direct RecordManager import from graph_sync module top-level - Move RecordManager import to factory function where needed - Ensure real-time graph sync works in jetstream_consumer context 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/graph_sync.py | 9 ++++----- src/record_manager.py | 9 ++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/graph_sync.py b/src/graph_sync.py index 50bfed1..b70fa58 100644 --- a/src/graph_sync.py +++ b/src/graph_sync.py @@ -13,8 +13,6 @@ import json from neo4j import GraphDatabase from atproto import Client as AtProtoClient -from record_manager import RecordManager - # Configure logging logging.basicConfig( level=logging.INFO, @@ -51,7 +49,7 @@ class GraphSyncService: ] def __init__(self, neo4j_uri: str, neo4j_user: str, neo4j_password: str, - record_manager: RecordManager): + record_manager: Any = None): """ Initialize the Graph Sync Service. @@ -59,7 +57,7 @@ class GraphSyncService: neo4j_uri: Neo4j connection URI (e.g., "bolt://localhost:7687") neo4j_user: Neo4j username neo4j_password: Neo4j password - record_manager: Authenticated RecordManager instance + record_manager: Authenticated RecordManager instance (optional) """ self.record_manager = record_manager self.driver = GraphDatabase.driver(neo4j_uri, auth=(neo4j_user, neo4j_password)) @@ -527,7 +525,7 @@ class GraphSyncService: def create_graph_sync_service(neo4j_uri: str = "bolt://localhost:7687", neo4j_user: str = "neo4j", neo4j_password: str = "comind123", - record_manager: Optional[RecordManager] = None) -> GraphSyncService: + record_manager: Any = None) -> GraphSyncService: """ Factory function to create a GraphSyncService instance. @@ -542,6 +540,7 @@ def create_graph_sync_service(neo4j_uri: str = "bolt://localhost:7687", """ if record_manager is None: from session_reuse import default_login + from record_manager import RecordManager client = default_login() record_manager = RecordManager(client) diff --git a/src/record_manager.py b/src/record_manager.py index 81595af..5329c07 100644 --- a/src/record_manager.py +++ b/src/record_manager.py @@ -68,7 +68,14 @@ class RecordManager: def _initialize_graph_sync(self): """Initialize the graph sync service if dependencies are available.""" try: - from graph_sync import create_graph_sync_service + # Try different import paths depending on execution context + try: + from src.graph_sync import create_graph_sync_service + except ImportError: + try: + from graph_sync import create_graph_sync_service + except ImportError: + from .graph_sync import create_graph_sync_service # Get Neo4j connection parameters from environment or use defaults neo4j_uri = os.getenv("COMIND_NEO4J_URI", "bolt://localhost:7687") -- 2.51.2