Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support duckdb 1.1.0, update globals() for scanning #2279

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion marimo/_sql/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from marimo._output.rich_help import mddoc
from marimo._plugins.ui._impl import table
from marimo._runtime import output
from marimo._runtime.context.types import (
ContextNotInitializedError,
get_context,
)


def get_default_result_limit() -> Optional[int]:
Expand Down Expand Up @@ -37,7 +41,22 @@ def sql(

import duckdb # type: ignore[import-not-found,import-untyped,unused-ignore] # noqa: E501

relation = duckdb.sql(query=query)
# In Python globals() are scoped to modules; since this function
# is in a different module than user code, globals() doesn't return
# the kernel globals, it just returns this module's global namespace.
#
# However, duckdb needs access to the kernel's globals. For this reason,
# we manually exec duckdb and provide it with the kernel's globals.
try:
ctx = get_context()
except ContextNotInitializedError:
relation = duckdb.sql(query=query)
else:
relation = eval(
"duckdb.sql(query=query)",
ctx.globals,
{"query": query, "duckdb": duckdb},
)

if not relation:
return None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ dev = [
# For server testing
"httpx~=0.27.0",
# For SQL
"duckdb~=1.0.0",
"duckdb~=1.1.0",
# For testing mo.ui.chart, dataframes, tables
"pandas>=1.5.3",
"pandas-stubs>=1.5.3.230321",
Expand Down
Loading