Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(seed): pass connection string to DBIngestor and stop mislabeling OSError in load_from_database (#995)
yzxcj7978639cb9f162e
diff --git a/semantica/seed/seed_manager.py b/semantica/seed/seed_manager.pyindex 5051697d..16f21ea1 100644--- a/semantica/seed/seed_manager.py+++ b/semantica/seed/seed_manager.py@@ -401,18 +401,25 @@ class SeedDataManager:"""try:from ..ingest.db_ingestor import DBIngestor+ except ImportError as e:+ raise ProcessingError(+ "Database ingestion module not available. Install required dependencies."+ ) from e+ try:# Initialize DB ingestordb_ingestor = DBIngestor(config={"connection_string": connection_string})- # Execute query or export table+ # Execute query or export table. Both ingestor methods take the+ # connection string as their first argument — the constructor's+ # config is not a substitute for it (#973).if query:# Execute custom query- result = db_ingestor.execute_query(query)+ result = db_ingestor.execute_query(connection_string, query)records = result if isinstance(result, list) else [result]elif table_name:# Export table- table_data = db_ingestor.export_table(table_name)+ table_data = db_ingestor.export_table(connection_string, table_name)records = table_data.rows if hasattr(table_data, "rows") else []else:raise ProcessingError("Either 'query' or 'table_name' must be provided")@@ -429,11 +436,11 @@ class SeedDataManager:self.logger.info(f"Loaded {len(records)} records from database")return records- except (ImportError, OSError):- raise ProcessingError(- "Database ingestion module not available. Install required dependencies."- )+ except ProcessingError:+ raiseexcept Exception as e:+ # OSError here is a real connection/driver failure, not a missing+ # module — report the actual cause and keep the chain (#973).raise ProcessingError(f"Failed to load from database: {e}") from edef load_from_api(diff --git a/tests/test_seed_manager.py b/tests/test_seed_manager.pyindex 31f966f1..c66149cc 100644--- a/tests/test_seed_manager.py+++ b/tests/test_seed_manager.py@@ -126,7 +126,11 @@ def test_load_from_database(mock_db_ingestor_cls, seed_manager):assert len(records) == 1assert records[0]["id"] == 1assert records[0]["entity_type"] == "User"- mock_db_ingestor.execute_query.assert_called_once_with("SELECT * FROM users")+ # Regression for #973: the ingestor methods receive the connection+ # string as their first argument — the constructor config is not enough.+ mock_db_ingestor.execute_query.assert_called_once_with(+ "sqlite:///:memory:", "SELECT * FROM users"+ )# Mock export_table resultmock_table_data = MagicMock()@@ -139,6 +143,23 @@ def test_load_from_database(mock_db_ingestor_cls, seed_manager):)assert len(records) == 1assert records[0]["id"] == 2+ mock_db_ingestor.export_table.assert_called_once_with("sqlite:///:memory:", "users")++def test_load_from_database_os_error_not_misreported(seed_manager):+ # Regression for #973: a real OSError from the ingestor must surface as a+ # database failure with the cause chained, not as a missing module.+ import semantica.ingest.db_ingestor as dbi++ with patch.object(+ dbi.DBIngestor, "execute_query", side_effect=OSError(111, "Connection refused")+ ):+ with pytest.raises(ProcessingError) as excinfo:+ seed_manager.load_from_database(+ "postgresql://u:[email protected]/db", query="SELECT 1"+ )+ assert "Failed to load from database" in str(excinfo.value)+ assert "module not available" not in str(excinfo.value)+ assert isinstance(excinfo.value.__cause__, OSError)def test_load_from_database_import_error(seed_manager):with patch.dict("sys.modules", {"semantica.ingest.db_ingestor": None}):