Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

more try catches for datasource introspection (#6171)

Shahmir Varqhaca91c654f74a
diff --git a/marimo/_sql/engines/ibis.py b/marimo/_sql/engines/ibis.py
index 6358beba99..5265b237e1 100644
--- a/marimo/_sql/engines/ibis.py
+++ b/marimo/_sql/engines/ibis.py
@@ -103,22 +103,29 @@ class IbisEngine(SQLConnection["SQLBackend"]):
try:
database_name = self._connection.current_catalog
except AttributeError:
- pass
+ LOGGER.debug("Backend doesn't support current_catalog")
+ except Exception:
+ LOGGER.debug("Failed to get default database", exc_info=True)
if database_name is None:
try:
database_name = self._connection.name
except AttributeError:
- pass
+ LOGGER.debug("Backend doesn't have a connection name")
+ except Exception:
+ LOGGER.debug("Failed to get default database", exc_info=True)
return database_name
def get_default_schema(self) -> Optional[str]:
"""Get the default schema name"""
+ schema_name = None
try:
- schema_name: str | None = self._connection.current_database
+ schema_name = self._connection.current_database
except AttributeError:
- schema_name = None
+ LOGGER.debug("Backend doesn't support current_database")
+ except Exception:
+ LOGGER.debug("Failed to get default schema", exc_info=True)
return schema_name
@@ -148,10 +155,14 @@ class IbisEngine(SQLConnection["SQLBackend"]):
# For other Ibis backends, use original logic
databases = []
- if hasattr(self._connection, "list_catalogs"):
- database_names = self._connection.list_catalogs()
- else:
- database_names = [self.default_database]
+ try:
+ if hasattr(self._connection, "list_catalogs"):
+ database_names = self._connection.list_catalogs()
+ else:
+ database_names = [self.default_database]
+ except Exception:
+ LOGGER.debug("Failed to get databases", exc_info=True)
+ return []
for database_name in database_names:
if self._resolve_should_auto_discover(include_schemas):
diff --git a/marimo/_sql/get_engines.py b/marimo/_sql/get_engines.py
index 1cca757919..9b2bdb21ea 100644
--- a/marimo/_sql/get_engines.py
+++ b/marimo/_sql/get_engines.py
@@ -82,22 +82,25 @@ def engine_to_data_source_connection(
display_name=variable_name,
)
- default_database = engine.get_default_database()
- default_schema = engine.get_default_schema()
- inference_config = engine.inference_config
-
- config = get_datasources_config()
- databases = engine.get_databases(
- include_schemas=config.get(
- "auto_discover_schemas", inference_config.auto_discover_schemas
- ),
- include_tables=config.get(
- "auto_discover_tables", inference_config.auto_discover_tables
- ),
- include_table_details=config.get(
- "auto_discover_columns", inference_config.auto_discover_columns
- ),
- )
+ try:
+ default_database = engine.get_default_database()
+ default_schema = engine.get_default_schema()
+ inference_config = engine.inference_config
+
+ config = get_datasources_config()
+ databases = engine.get_databases(
+ include_schemas=config.get(
+ "auto_discover_schemas", inference_config.auto_discover_schemas
+ ),
+ include_tables=config.get(
+ "auto_discover_tables", inference_config.auto_discover_tables
+ ),
+ include_table_details=config.get(
+ "auto_discover_columns", inference_config.auto_discover_columns
+ ),
+ )
+ except Exception as e:
+ LOGGER.warning(f"Failed to introspect datasource: {e}")
display_name = (
f"{engine.dialect} ({variable_name})"
diff --git a/tests/_sql/test_get_engines.py b/tests/_sql/test_get_engines.py
index 50a35112e7..f5bfe14c99 100644
--- a/tests/_sql/test_get_engines.py
+++ b/tests/_sql/test_get_engines.py
@@ -100,6 +100,22 @@ def test_engine_to_data_source_connection() -> None:
assert connection.display_name == f"{backend_name} ({var_name})"
[email protected](not HAS_IBIS, reason="Ibis not installed")
+def test_engine_to_datasource_connection_error() -> None:
+ ibis_engine = IbisEngine(MagicMock())
+
+ # Mock the get_databases method to raise an error
+ ibis_engine.get_databases = MagicMock(
+ side_effect=Exception("Database connection failed")
+ )
+
+ connection = engine_to_data_source_connection(
+ VariableName("my_ibis"), ibis_engine
+ )
+ assert isinstance(connection, DataSourceConnection)
+ assert connection.databases == []
+
+
@pytest.mark.skipif(not HAS_DUCKDB, reason="DuckDB not installed")
def test_get_engines_from_variables_duckdb():
import duckdb