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 for module type for sql engine (#6103)

Shahmir Varqhabaa6a8eee115
diff --git a/marimo/_sql/engines/dbapi.py b/marimo/_sql/engines/dbapi.py
index e4a0219803..7b58f3dc00 100644
--- a/marimo/_sql/engines/dbapi.py
+++ b/marimo/_sql/engines/dbapi.py
@@ -1,6 +1,7 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations
+from types import ModuleType
from typing import TYPE_CHECKING, Any, Optional, Protocol
from marimo import _loggers
@@ -100,6 +101,11 @@ class DBAPIEngine(QueryEngine[DBAPIConnection]):
- rollback() method
- close() method
"""
+
+ # Imports like duckdb should not be treated as DB-API connections
+ if isinstance(var, ModuleType):
+ return False
+
try:
required_methods = ["cursor", "commit", "rollback", "close"]
has_required_methods = all(
diff --git a/tests/_sql/test_get_engines.py b/tests/_sql/test_get_engines.py
index 8a3a4bceb1..b32ef5281a 100644
--- a/tests/_sql/test_get_engines.py
+++ b/tests/_sql/test_get_engines.py
@@ -114,6 +114,17 @@ def test_get_engines_from_variables_duckdb():
assert isinstance(engine, DuckDBEngine)
[email protected](not HAS_DUCKDB, reason="DuckDB not installed")
+def test_get_engines_from_variables_import_module_type():
+ import duckdb
+
+ variables: list[tuple[str, object]] = [("duckdb", duckdb)]
+
+ # DuckDB import should not trigger a DuckDBEngine registration
+ engines = get_engines_from_variables(variables)
+ assert len(engines) == 0
+
+
@pytest.mark.skipif(not HAS_CLICKHOUSE, reason="Clickhouse not installed")
def test_get_engines_from_variables_clickhouse():
import chdb