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
Confirmed the bug is reproduced. Now let's design the fix.
Assistant
Good, treats it as a set of names. Keeping
DirectedGraph.get_multiply_defined()returninglist[Name](as before) whileDefinitionRegistry.get_multiply_defined()returns tuples is consistent with the interface description (only definitions.py function changes signature).Assistant
All existing tests pass currently. Now let's implement the fix carefully.
Assistant
This confirms
check_for_multiple_definitions(viacheck_for_errors) is the actual runtime path producing the error in the issue. We must fix this too, using conflict-aware grouping instead of rawgraph.definitions[name].Assistant
Now let's edit the file.
Assistant
Now let's update
get_multiply_defined:Assistant
Now let's update
graph.py'sget_multiply_definedwrapper to keep returninglist[Name].Assistant
Now let's fix
_lint/validate_graph.py'scheck_for_multiple_definitionsto use conflict-aware grouping.Assistant
Now let's re-run reproduction script and the test suites.
Assistant
Bug fixed. Now let's run the full test suites related to dataflow, lint, and other affected callers.
Assistant
Good, those pass once pytest-asyncio is installed (environment setup issue, unrelated to our change).
Assistant
All pass now. Let's run broader test suite touching runtime, ast, convert, code_mode, ai tools.
Assistant
Confirmed these are pre-existing failures unrelated to my change (environment specific: uv/pixi, tracing, args parsing). Let's restore my changes.
Assistant
Now let's check the remaining 4 failures unique to my change: duckdb_wasm ones — let's verify those are pre-existing too.
Assistant
All 26 failing tests are pre-existing environment issues, unrelated to my changes. Now let's run the broader test suite more targeted around dataflow, sql, edges, and app-multiply-define related tests to be thorough.
Assistant
All the same pre-existing failures, nothing new introduced. Let's also test
test_edges.py's skipped duckdb tests by installing polars properly, and checktest_ai_toolscode_mode multiply defined tests specifically.Assistant
All pass. Now let's write a more thorough reproduction/edge-case test script covering the scenarios described in the eval contract.
Assistant
All edge cases behave correctly. Now let's test the runtime-level error path (
check_for_errors) to make sure the actual "cell wasn't run" scenario from the issue is resolved end-to-end.Assistant
Excellent - this confirms the full end-to-end fix (the exact runtime code path that produces the error in the issue). Let's clean up temp files and run the full relevant test suite once more to be safe, then review the diff.
Assistant
No usage there currently. Now let's run the full broader test suite one more time to check nothing else broke, then check mypy/type checking if available.
Assistant
All these are the same pre-existing (environment-related) failures confirmed earlier. Let's also run the full test file for
tests/_ai/tools/tools/test_dependency_graph.pyspecifically, and checkmypy/type checking on the changed files if configured.Assistant
No type errors reported specifically in our changed files (all errors are in unrelated pre-existing files). Good. Let's also check
rufffor style consistency.Assistant
Those are pre-existing style warnings unrelated to my changes. Let's confirm none are new in my edited regions.
Assistant
These pre-existing warnings are unrelated to the lines I edited (all pre-existing property docstrings). Good, no new lint issues introduced. Now let's do a final full diff review.
Assistant
Now let's run the complete relevant test suite once more as a final sanity check before submission.
Assistant
Only the same 2 pre-existing unrelated failures remain (already confirmed to fail on the baseline too). The fix is complete and verified.
Assistant
This looks complete and correct. Let's go through the checklist:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.