ISSUE DESCRIPTION 🐛 Bug ❓: Variable name collision for SQL cells using same table name…
- User
ISSUE DESCRIPTION
🐛 Bug ❓: Variable name collision for SQL cells using same table name in different schemas
Discussed in https://github.com/marimo-team/marimo/discussions/9734
Originally posted by EED85 May 31, 2026
Description
When using multiple SQL cells in marimo with DuckDB, creating tables with the same name in different schemas leads to a variable redefinition error.
Although the tables are fully qualified and valid in DuckDB, marimo raises an error due to internal variable name collisions.
Minimal Reproducible Example
sql-- Cell 1 CREATE TABLE finance.datalake.xx (id INT);sql-- Cell 2 CREATE TABLE finance.information_layer.xx (id INT);ERROR
codeThis cell wasn't run because it has errors This cell redefines variables from other cells. 'xx' was also defined by: dl Fix: Wrap in a function Why can't I redefine variables?Expected Behavior
Since the tables are created in different schemas, both statements should execute without conflict:
Environment
coderequires-python = ">=3.13" dependencies = [ "duckdb", "ipykernel>=7.2.0", "marimo>=0.23.8", "pandas>=3.0.3", "plotly>=6.7.0", "polars>=1.41.2", "pyarrow>=24.0.0", "pydantic-ai>=1.104.0", "ruff>=0.15.15", "sqlglot<30", "tabulate>=0.10.0", ]That is my opinion. What is the marimo way, to handle this?
Best Eric
Evaluation contract
Track SQL definitions by their complete qualified identity. Tables with the same leaf name in different schemas or catalogs are not multiply defined; the same fully qualified name, or the same unqualified name, still is. Preserve the user-facing table variable, defining-cell ownership, deletion behavior, and conflict reporting for genuine collisions.
Interface
Assistant
There's a .venv already. Let's use it.
Assistant
Now let's reproduce the issue with the venv python.
Assistant
Reproduced. Now let's design the fix in
definitions.py.Assistant
Let's look at test_sql_chain, test_sql_tree_with_declared_df, test_attached_db and other sql tests for context before making changes.
Assistant
Now let's update
get_multiply_definedat the bottom of definitions.py.Assistant
Now update
graph.py'sget_multiply_definedwrapper to keep returninglist[Name]for backward compatibility.Assistant
Now let's check the full definitions.py file for correctness.
Assistant
Now let's run the reproduce script and existing tests.
Assistant
The fix works correctly. Now let's run the full test suite for dataflow, edges, dependency_graph, and other related tests.
Assistant
All 94 tests pass now, including the previously skipped ones. Let's also run the broader test suite for related modules that use
get_multiply_defined.Assistant
Let's run tests for
_code_mode,_ast/app, and_convert/ipynbas well, since they consumeget_multiply_defined.Assistant
Confirmed pre-existing failures unrelated to our change. Let's restore our changes.
Assistant
Now let's run other relevant test suites:
_code_modeexcluding TestPackages,_convert/ipynb, and the broader_runtimeand_aitest suites.Assistant
All passing. Now let's run broader
_runtimetests and_aitests to be safe.Assistant
Confirmed pre-existing environment-related failure (unrelated to our change, requires
setsidpermission). Now let's run the_aitests and_asttests fully.Assistant
All pass. Now let's double check the diff and also write a quick end-to-end reproduction using the actual scenario with duckdb to simulate app-level execution to fully confirm the fix resolves the user issue.
Assistant
Let's verify this fails without our fix (revert temporarily to confirm).
Assistant
Confirmed: reproduces the bug without fix, and fixed with our patch. Let's also verify a genuine conflict (same schema, same table twice) is still caught.
Assistant
Genuine conflicts are still correctly detected. Let's also test unqualified duplicate table names (no schema) still conflict.
Assistant
Excellent, all edge cases work correctly. Let's view the final diff.
Assistant
Let's also check ruff formatting since the project likely uses it.
Assistant
These are pre-existing lint issues unrelated to our change (in unrelated properties). Let's confirm with
git diffscope that our changes don't add new violations.Assistant
Confirmed pre-existing, same 5 errors before our changes. Our patch introduces no new lint issues.
Assistant
Let's apply the formatting fix.
Assistant
Now let's do a final full re-run of the relevant test suites to make sure everything still passes after formatting change.
Assistant
All pass. Let's view the final diff once more.
Assistant
The changes look clean and complete. Let's clean up temp files and do one last comprehensive check.
Assistant
Checklist Review
-
Yes. I created a reproduction script using with and in two separate cells, and confirmed it raised on the original code.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.