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.

check if default schema and db is string, for engines (#6438)

Shahmir Varqha079ac6ada2d5
diff --git a/marimo/_sql/engines/ibis.py b/marimo/_sql/engines/ibis.py
index 5265b237e1..eff450546e 100644
--- a/marimo/_sql/engines/ibis.py
+++ b/marimo/_sql/engines/ibis.py
@@ -101,7 +101,7 @@ class IbisEngine(SQLConnection["SQLBackend"]):
"""
database_name = None
try:
- database_name = self._connection.current_catalog
+ database_name = str(self._connection.current_catalog)
except AttributeError:
LOGGER.debug("Backend doesn't support current_catalog")
except Exception:
@@ -109,7 +109,7 @@ class IbisEngine(SQLConnection["SQLBackend"]):
if database_name is None:
try:
- database_name = self._connection.name
+ database_name = str(self._connection.name)
except AttributeError:
LOGGER.debug("Backend doesn't have a connection name")
except Exception:
@@ -121,7 +121,7 @@ class IbisEngine(SQLConnection["SQLBackend"]):
"""Get the default schema name"""
schema_name = None
try:
- schema_name = self._connection.current_database
+ schema_name = str(self._connection.current_database)
except AttributeError:
LOGGER.debug("Backend doesn't support current_database")
except Exception:
@@ -165,9 +165,10 @@ class IbisEngine(SQLConnection["SQLBackend"]):
return []
for database_name in database_names:
+ database_name_str = str(database_name)
if self._resolve_should_auto_discover(include_schemas):
schemas = self._get_schemas(
- database=database_name,
+ database=database_name_str,
include_tables=self._resolve_should_auto_discover(
include_tables
),
@@ -179,7 +180,7 @@ class IbisEngine(SQLConnection["SQLBackend"]):
schemas = []
database: Database = Database(
- name=database_name,
+ name=database_name_str,
dialect=self.dialect,
schemas=schemas,
engine=self._engine_name,
diff --git a/marimo/_sql/engines/redshift.py b/marimo/_sql/engines/redshift.py
index e087eff7e0..406e9bfc6e 100644
--- a/marimo/_sql/engines/redshift.py
+++ b/marimo/_sql/engines/redshift.py
@@ -157,7 +157,10 @@ class RedshiftEngine(SQLConnection["Connection"]):
with self._connection.cursor() as cursor:
try:
result = cursor.execute("SELECT current_schema()")
- return str(result.fetchone()[0])
+ row = result.fetchone()
+ if row is None or row[0] is None:
+ return None
+ return str(row[0])
except Exception as e:
LOGGER.debug("Failed to get default schema. Reason: %s.", e)
return None
@@ -337,7 +340,10 @@ class RedshiftEngine(SQLConnection["Connection"]):
row_count = cursor.execute(
f"SELECT COUNT(*) FROM {database_name}.{schema_name}.{table_name}"
)
- num_rows = row_count.fetchone()[0]
+ row = row_count.fetchone()
+ if row is None or row[0] is None:
+ return None
+ num_rows = row[0]
try:
# [[catalog, schema, table_name, column_name, ordinal_position, column_default, is_nullable, data_type, character_maximum_length, numeric_precision, numeric_scale, remarks]]
diff --git a/marimo/_sql/engines/sqlalchemy.py b/marimo/_sql/engines/sqlalchemy.py
index 762a284b36..f083285934 100644
--- a/marimo/_sql/engines/sqlalchemy.py
+++ b/marimo/_sql/engines/sqlalchemy.py
@@ -122,8 +122,10 @@ class SQLAlchemyEngine(SQLConnection["Engine"]):
from sqlalchemy import text
try:
- if self._connection.url.database is not None:
- return self._connection.url.database
+ if self._connection.url.database is not None and isinstance(
+ self._connection.url.database, str
+ ):
+ return str(self._connection.url.database)
except Exception:
LOGGER.warning("Connection URL is invalid", exc_info=True)
return None
@@ -166,7 +168,14 @@ class SQLAlchemyEngine(SQLConnection["Engine"]):
return None
try:
- return self.inspector.default_schema_name
+ default_schema_name = self.inspector.default_schema_name
+ # https://github.com/marimo-team/marimo/issues/6436.
+ # Upstream bug where default schema name is not a string.
+ if default_schema_name is None or not isinstance(
+ default_schema_name, str
+ ):
+ return None
+ return str(default_schema_name)
except Exception:
LOGGER.warning("Failed to get default schema name", exc_info=True)
return None
@@ -270,9 +279,12 @@ class SQLAlchemyEngine(SQLConnection["Engine"]):
except Exception:
LOGGER.warning("Failed to get tables in schema", exc_info=True)
return []
- tables: list[tuple[DataTableType, str]] = [
- ("table", name) for name in table_names
- ] + [("view", name) for name in view_names]
+
+ tables: list[tuple[DataTableType, str]] = []
+ for name in table_names:
+ tables.append(("table", name))
+ for name in view_names:
+ tables.append(("view", name))
if not include_table_details:
return [