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: remove dml warning; add test (#4168)
Myles Scolnick931a937f58ae
diff --git a/marimo/_ast/sql_visitor.py b/marimo/_ast/sql_visitor.pyindex 027cc6dd6b..f080e4e040 100644--- a/marimo/_ast/sql_visitor.py+++ b/marimo/_ast/sql_visitor.py@@ -361,17 +361,12 @@ def find_sql_refs(if expression is None:continue- if is_dml := bool(expression.find(exp.Update, exp.Insert, exp.Delete)):+ if bool(expression.find(exp.Update, exp.Insert, exp.Delete)):for table in expression.find_all(exp.Table):append_refs_from_table(table)# build_scope only works for select statementsif root := build_scope(expression):- if is_dml:- LOGGER.warning(- "Scopes should not exist for dml's, may need rework if this occurs"- )-for scope in root.traverse(): # type: ignorefor _node, source in scope.selected_sources.values():if isinstance(source, exp.Table):diff --git a/tests/_ast/test_sql_visitor.py b/tests/_ast/test_sql_visitor.pyindex d1aa291069..37fcc901a2 100644--- a/tests/_ast/test_sql_visitor.py+++ b/tests/_ast/test_sql_visitor.py@@ -731,3 +731,34 @@ class TestFindSQLRefs:def test_find_sql_refs_invalid_sql() -> None:sql = "SELECT * FROM"assert find_sql_refs(sql) == []++ @staticmethod+ def test_dml_with_subquery() -> None:+ # first+ sql = """+ insert into table1 (column1) select distinct column1 from table2 order by random();+ """+ assert find_sql_refs(sql) == [+ "table1",+ "table2",+ ]++ # second+ sql = """+ update table3 set column1=(select column2 from table1 t where t.column1=table3.column1);+ """+ assert find_sql_refs(sql) == [+ "table3",+ "table1",+ ]++ # combined+ sql = """+ insert into table1 (column1) select distinct column1 from table2 order by random();+ update table3 set column1=(select column2 from table1 t where t.column1=table3.column1);+ """+ assert find_sql_refs(sql) == [+ "table1",+ "table2",+ "table3",+ ]