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 sql references (#1912)
Akshay Agrawal1a2af1a50034
diff --git a/marimo/_ast/visitor.py b/marimo/_ast/visitor.pyindex c8dfa50864..53ab4aa19e 100644--- a/marimo/_ast/visitor.py+++ b/marimo/_ast/visitor.py@@ -397,7 +397,10 @@ class ScopedVisitor(ast.NodeVisitor):returnfor table in tables:- self._add_ref(table, deleted=False)+ # Table may be a URL or something else that+ # isn't a Python variable+ if table.isidentifier():+ self._add_ref(table, deleted=False)# Visit arguments, keyword args, etc.self.generic_visit(node)diff --git a/marimo/_tutorials/sql.py b/marimo/_tutorials/sql.pyindex 2163e380ef..4dd3a487c1 100644--- a/marimo/_tutorials/sql.py+++ b/marimo/_tutorials/sql.py@@ -1,7 +1,8 @@# Copyright 2024 Marimo. All rights reserved.+import marimo-__generated_with = "0.7.1"+__generated_with = "0.7.12"app = marimo.App()@@ -155,7 +156,7 @@ def __(df, mo):@app.cell(hide_code=True)def __(mo):- mo.md(r"Let's look at another SQL statement, but this time with a UI element")+ mo.md(r"""Let's look at another SQL statement, but this time with a UI element""")return@@ -295,7 +296,7 @@ def __(mo):@app.cell-def __(mo):+def __(cars, mo):cars = mo.sql(f"""-- Download a CSV and create an in-memory table@@ -318,7 +319,7 @@ def __(cars, mo):@app.cell-def __(cylinders_dropdown, mo, origin_dropdown):+def __(cars, cylinders_dropdown, mo, origin_dropdown):filtered_cars = mo.sql(f"""SELECT * FROM carsdiff --git a/tests/_ast/test_visitor.py b/tests/_ast/test_visitor.pyindex 3e48a07fa7..6ae10f0f54 100644--- a/tests/_ast/test_visitor.py+++ b/tests/_ast/test_visitor.py@@ -985,6 +985,21 @@ def test_sql_from_another_module() -> None:assert v.refs == set(["lib"])[email protected](not HAS_DEPS, reason="Requires duckdb")+def test_sql_statement_with_url() -> None:+ code = "\n".join(+ [+ 'mo.sql("CREATE OR replace TABLE cars as '+ "FROM 'https://datasets.marimo.app/cars.csv';\")",+ ]+ )+ v = visitor.ScopedVisitor()+ mod = ast.parse(code)+ v.visit(mod)+ assert v.defs == set()+ assert v.refs == set(["mo"])++@pytest.mark.skipif(not HAS_DEPS, reason="Requires duckdb")def test_unparsable_sql_doesnt_fail() -> None:code = "\n".join(