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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: default to opt-in for introspection of tables (#3940)
Shahmir Varqhaf020fe5cb7b1
diff --git a/docs/guides/working_with_data/sql.md b/docs/guides/working_with_data/sql.mdindex 4d3b1856c7..05e0c006af 100644--- a/docs/guides/working_with_data/sql.md+++ b/docs/guides/working_with_data/sql.md@@ -187,6 +187,17 @@ marimo will automatically discover the database connection and display the datab</figure></div>+???+ note++ By default, marimo auto-discovers databases and schemas, but not tables and columns (to avoid performance issues with large databases). You can configure this behavior in your `pyproject.toml` file:++ ```toml title="pyproject.toml"+ [tool.marimo.datasources]+ auto_discover_schemas = true # Default: true+ auto_discover_tables = false # Default: false - enable for table auto-discovery+ auto_discover_columns = false # Default: false - enable for column auto-discovery+ ```+## Interactive tutorialFor an interactive tutorial, rundiff --git a/frontend/src/components/datasources/datasources.tsx b/frontend/src/components/datasources/datasources.tsxindex 080a475e55..69bfa3107f 100644--- a/frontend/src/components/datasources/datasources.tsx+++ b/frontend/src/components/datasources/datasources.tsx@@ -379,7 +379,20 @@ const TableList: React.FC<{searchValue?: string;}> = ({ tables, sqlTableContext, searchValue }) => {if (tables.length === 0) {- return <EmptyState content="No tables found" className="pl-9" />;+ // TODO: We should preview tables instead of disabling introspection+ return (+ <div className="text-sm text-muted-foreground py-1 pl-9">+ No tables found or{" "}+ <a+ className="text-link"+ href="https://docs.marimo.io/guides/working_with_data/sql/#database-schema-and-table-auto-discovery"+ target="_blank"+ rel="noreferrer"+ >+ introspection is disabled+ </a>+ </div>+ );}const filteredTables = tables.filter((table) => {diff --git a/marimo/_config/config.py b/marimo/_config/config.pyindex 013fc441d6..ecee64197c 100644--- a/marimo/_config/config.py+++ b/marimo/_config/config.py@@ -257,6 +257,22 @@ class SnippetsConfig(TypedDict):include_default_snippets: NotRequired[bool]+@dataclass+class DatasourcesConfig(TypedDict):+ """Configuration for datasources panel.++ **Keys.**++ - `auto_discover_schemas`: if `True`, include schemas in the datasource+ - `auto_discover_tables`: if `True`, include tables in the datasource+ - `auto_discover_columns`: if `True`, include columns & table metadata in the datasource+ """++ auto_discover_schemas: NotRequired[bool]+ auto_discover_tables: NotRequired[bool]+ auto_discover_columns: NotRequired[bool]++@mddoc@dataclassclass MarimoConfig(TypedDict):@@ -273,6 +289,7 @@ class MarimoConfig(TypedDict):ai: NotRequired[AiConfig]experimental: NotRequired[dict[str, Any]]snippets: NotRequired[SnippetsConfig]+ datasources: NotRequired[DatasourcesConfig]@mddoc@@ -291,6 +308,7 @@ class PartialMarimoConfig(TypedDict, total=False):ai: NotRequired[AiConfig]experimental: NotRequired[dict[str, Any]]snippets: SnippetsConfig+ datasources: NotRequired[DatasourcesConfig]DEFAULT_CONFIG: MarimoConfig = {diff --git a/marimo/_sql/get_engines.py b/marimo/_sql/get_engines.pyindex 1449bfdfac..de0cc834ce 100644--- a/marimo/_sql/get_engines.py+++ b/marimo/_sql/get_engines.py@@ -4,7 +4,13 @@ from __future__ import annotationsfrom typing import Any, castfrom marimo import _loggers+from marimo._config.config import DatasourcesConfig+from marimo._config.manager import get_default_config_managerfrom marimo._data.models import Database, DataSourceConnection+from marimo._runtime.context.types import (+ ContextNotInitializedError,+ get_context,+)from marimo._sql.engines import (INTERNAL_DUCKDB_ENGINE,DuckDBEngine,@@ -47,10 +53,11 @@ def engine_to_data_source_connection() -> DataSourceConnection:databases: list[Database] = []if isinstance(engine, SQLAlchemyEngine):+ config = get_datasources_config()databases = engine.get_databases(- include_schemas=True,- include_tables=True,- include_table_details=False,+ include_schemas=config.get("auto_discover_schemas", True),+ include_tables=config.get("auto_discover_tables", False),+ include_table_details=config.get("auto_discover_columns", False),)elif isinstance(engine, DuckDBEngine):databases = engine.get_databases()@@ -72,3 +79,26 @@ def engine_to_data_source_connection(display_name=display_name,databases=databases,)+++def get_datasources_config() -> DatasourcesConfig:+ try:+ return get_context().marimo_config.get("datasources", {})+ except ContextNotInitializedError:+ pass+ except Exception as e:+ LOGGER.warning(+ f"Failed to get datasources config from context: {e}. Falling back to default config."+ )++ try:+ return (+ get_default_config_manager(current_path=None)+ .get_config()+ .get("datasources", {})+ )+ except Exception as e:+ LOGGER.warning(+ f"Failed to get datasources config from default config: {e}. Returning empty config."+ )+ return {}diff --git a/openapi/api.yaml b/openapi/api.yamlindex 1c2ad3e6b5..722ec344ce 100644--- a/openapi/api.yaml+++ b/openapi/api.yaml@@ -1266,6 +1266,15 @@ components:- activate_on_typing- copilottype: object+ datasources:+ properties:+ auto_discover_columns:+ type: boolean+ auto_discover_schemas:+ type: boolean+ auto_discover_tables:+ type: boolean+ type: objectdisplay:properties:cell_output:@@ -2207,7 +2216,7 @@ components:type: objectinfo:title: marimo API- version: 0.11.11+ version: 0.11.12openapi: 3.1.0paths:/@file/{filename_and_length}:diff --git a/openapi/src/api.ts b/openapi/src/api.tsindex 534c0666f1..93fd063b24 100644--- a/openapi/src/api.ts+++ b/openapi/src/api.ts@@ -2649,6 +2649,11 @@ export interface components {codeium_api_key?: string | null;copilot: boolean | ("github" | "codeium");};+ datasources?: {+ auto_discover_columns?: boolean;+ auto_discover_schemas?: boolean;+ auto_discover_tables?: boolean;+ };display: {/** @enum {string} */cell_output: "above" | "below";