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
-- Cell 1 CREATE TABLE finance.datalake.xx (id INT);-- Cell 2 CREATE TABLE finance.information_layer.xx (id INT);ERROR
This 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
requires-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
Type: Function Name: get_multiply_defined Path: marimo/_runtime/dataflow/definitions.py Input: self Output: list[tuple[Name, set[CellId_t]]] Description: Returns a list of (name, cell_ids) tuples for names that are defined in multiple cells. Uses conflict-aware grouping so that qualified SQL names (e.g., schema.table) with the same leaf name are not considered multiply defined unless they share the exact same qualified name.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted. Assistant
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Now let me look at the tests for this module to understand what's
Assistant
me look at the visitor module to understand
VariableDataandqualified_name:Assistant
Let me look at the SQL visitor and
qualified_name:Assistant
let me look at the tests for dataflow to better understand what's happening:
Assistant
Now let me understand the issue. The existing logic seems to be:
Assistant
I need to reproduce the bug. Let me look at how tests are set up:
Assistant
Now I understand the issue better. Let me write a reproducer:Now let me write a reproducer for the bug:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cat > /tmp/repro.py << 'EOF' """Reproducer for the SQL table name collision bug.""" from functools import partial from marimo._ast import compiler from marimo._runtime import dataflow
parse_cell = partial(compiler.compile_cell, cell_id="0")
graph = dataflow.DirectedGraph()
Cell 1: CREATE TABLE finance.datalake.xx
code1 = 'df1 = mo.sql("CREATE TABLE finance.datalake.xx (id INT)")' cell1 = parse_cell(code1) graph.register_cell("0", cell1)
print("After cell 1:") print(f" definitions: {dict(graph.definitions)}") print(f" multiply defined: {graph.get_multiply_defined()}")
Cell 2: CREATE TABLE finance.information_layer.xx
code2 = 'df2 = mo.sql("CREATE TABLE finance.information_layer.xx (id INT)")' cell2 = parse_cell(code2) graph.register_cell("1", cell2)
print("After cell 2:") print(f" definitions: {dict(graph.definitions)}") print(f" multiply defined: {graph.get_multiply_defined()}") EOF python /tmp/repro.py]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Let me try again with a properly structured tool call.
Assistant
Assistant
me check the existing tests for
register_definitionto understand expected behavior:Assistant
Now I need to look at all callers of
get_multiply_definedsince the return type changes:Assistant
Let me look at each caller more carefully:
Assistant
OK so this displays the first one. With tuples, we'd want to display the first name from the first tuple. Let me check the code_mode:OK so this displays the first one. Let me check the code_mode:Let me check the code_mode:How should I fix the issue? Let me think step by step:
- First, look at the runtime.py to understand how
MultipleDefinitionErroris raised. There's likely a place where it shows the user the conflicting cells and the name. </tool_call>
- First, look at the runtime.py to understand how
Assistant
Let me look at to_ir.py:OK so the code_mode uses
get_multiply_definedand usesget_defining_cellsto find the cells that already define the name. With our change, we have tuples (name, cell_ids), so we'd use the cell_ids directly.Let me look at to_ir.py:Let me look at to_ir.py:How should I fix the issue? Let me think step by step:
- First, look at the runtime.py to understand how
MultipleDefinitionErroris raised. There's likely a place where it shows the user the conflicting cells and the name.
- First, look at the runtime.py to understand how
Assistant
Let me check
dependency_graph.pymore thoroughly:OK soto_ir.pyuses the names as strings, transforming them if they're not referred to.Let me check
dependency_graph.pymore thoroughly:How should I fix the issue? Let me think step by step:- First, look at the runtime.py to understand how
MultipleDefinitionErroris raised. There's likely a place where it shows the user the conflicting cells and the name.
- First, look at the runtime.py to understand how
Assistant
me look at where the runtime.py raises the error with the user-friendly message:Let me look at the runtime.py to understand the error display:
Assistant
Now let me look at the messaging for the error display:Now let me look at the messaging for the error display:OK so this displays the first one. Let me check the code_mode:How should I fix the issue? Let me think step by step:
- First, look at the runtime.py to understand how
MultipleDefinitionErroris raised. There's likely a place where it shows the user the conflicting cells and the name. ]<]minimax[>[cat /marimo/marimo/_messaging/errors.py | head -80]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
- First, look at the runtime.py to understand how
Assistant
Now let me check the frontend display:
Assistant
Now let me look at the lint/breaking rules to understand the validation flow:Now let me check the linting rules:Let me check where the runtime uses it:
Assistant
Let me look at how typed_definitions is used elsewhere:Now let me see how typed_definitions is used elsewhere:Now let me see how typed_definitions is used elsewhere:
Assistant
Let me check what qualified_name is set to when there's no schema:Now let me check what qualified_name is set to when there's no schema:
Assistant
let me check what happens when the schema is "main" or empty:
Assistant
Now let me check views, schemas, catalogs:Now let me check views, schemas, catalogs:
Assistant
Let me look at the existing test more carefully:Now let me trace through the existing tests:
Assistant
look at the tests for
check_for_multiple_definitions:Assistant
Now let me check what tests check
definitionsdirectly:Assistant
Let me check matches_hierarchical_ref:
Assistant
Let me search for tests that check
definitions[name]:Assistant
Let me also check if there are tests that specifically assert definitions[name] contents:
Assistant
Now I have enough understanding. Let me write the fix:
Assistant
Now let me implement the changes. First, let me update
definitions.py:Assistant
Now let me test the reproducer to confirm the bug is fixed:
Assistant
The bug is fixed. Let me also test more cases:
Assistant
My test assertion was wrong -
dfis also multiply defined in Test 6. Let me fix the test:Assistant
All tests pass. Now I need to update the callers of
get_multiply_definedto handle the new return type. Let me start:Assistant
Now update the ipynb converter:
Assistant
Now let me update the dependency_graph.py:
Assistant
Now let me update the code_mode:
Assistant
Now let me update the
check_for_multiple_definitionsfunction:Assistant
Now let me also check if there are any other places that use
get_multiply_definedordefinition_registry.definitionsdirectly:Assistant
Let me also update the
graph.get_multiply_definedinterface to match the new return type:Assistant
Now let me run my reproducer to confirm the fix works end-to-end:
Assistant
Now let me run the existing tests to see what breaks:
Assistant
is an expected failure due to the interface change. Let me continue running tests without
-x:Assistant
2 tests fail, both due to the interface change (expected per instructions). Let me run other affected tests:
Assistant
I run individually it passes. Let me run the full test again:
Assistant
It passes when run alone. Maybe a test ordering issue. Let me see what happens when I run the snapshot tests together:It passes alone. Let me check if it's a test ordering issue:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[.venv/bin/python -m pytest tests/_lint/test_snapshot.py 2>&1 | tail -30]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Interesting - it passed. The issue is likely non-deterministic test ordering. Let me run it a few more times:Interesting - it passed this time. Let me run it multiple times to see if it's flaky:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[for i in 1 2 3; do echo "Run $i:"; .venv/bin/python -m pytest tests/_lint/test_snapshot.py 2>&1 | tail -5; done]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Yes, it's flaky. The failure shows different errors each time. Let me see what's happening more carefully:Yes, flaky! Let me look at the snapshot test to understand:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cat /marimo/tests/_lint/test_files/mixed_issues.py | head -100]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Assistant
I see. Let me also check how the test failure looks - it seems my non-deterministic order is causing the issue. Let me look at one specific failure:
Assistant
All passing now! Let me run more tests to ensure nothing is broken:All passing now! Let me run more tests to ensure nothing is broken:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[.venv/bin/python -m pytest tests/_lint/ 2>&1 | tail -10]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All lint tests pass. Now let me run other tests:
Assistant
Assistant
Only 3 failures, 2 of which are due to the interface change. Let me check the third one:Only 3 failures. Let me check the third one to see if it's related:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[.venv/bin/python -m pytest tests/_runtime/test_runtime.py::TestLaunchKernelEventLoop::test_non_windows_does_not_change_event_loop_policy -v 2>&1 | tail -30]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
This is a platform issue, not related to my change. The
os.setsid()fails because of sandbox restrictions. Not my concern.Let me run more tests to confirm:This is a platform issue unrelated to my change. Let me run more tests:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[.venv/bin/python -m pytest tests/_runtime/test_dataflow.py tests/_runtime/test_edges.py 2>&1 | tail -15]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Only the 2 expected failures. Let me check code_mode tests now:Only the 2 expected failures. Let me check code_mode tests now:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[.venv/bin/python -m pytest tests/_code_mode/ 2>&1 | tail -15]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
These failures look unrelated to my change - they're about packages management and pixi. Let me check by running them without my changes:These failures look unrelated to my change - they're about packages management and pixi. Let me check by running them without my changes:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[git stash && .venv/bin/python -m pytest tests/_code_mode/test_code_mode_context.py::TestPackages::test_add_single 2>&1 | tail -10 && git stash pop]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The test fails even without my changes. So it's a pre-existing failure unrelated to my changes.
Now let me also check the dataflow and other tests once more to make sure my changes don't break anything else:Confirmed - this test failure is pre-existing, unrelated to my change. Let me verify my changes don't break other tests:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[.venv/bin/python -m pytest tests/_runtime/test_dataflow_cases.py tests/_runtime/test_edges.py tests/_lint/ tests/_convert/ tests/_ai/tools/ 2>&1 | tail -20]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Only the 1 expected failure (test mock uses old return type). Let me also check that there aren't other places I missed updating.
Let me search for all uses of get_multiply_defined again:Only the 1 expected failure (test mock uses old return type). Let me also check that there aren't other places I missed updating.
Let me search for all uses of get_multiply_defined again:Only the 1 expected failure. Let me also search for all places that might use the old API:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[grep -rn "get_multiply_defined" /marimo/marimo/ /marimo/tests/ --include="*.py"]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Assistant
Assistant
Assistant
All edge cases pass. The view/table with same name in same schema is reported as a conflict (because they have the same identity), which is reasonable behavior since they share the same qualified name.
Now let me also re-run the test for the actual bug fix scenario. Let me also make sure the user's example works correctly:All edge cases pass! Let me also verify the user's bug case works correctly:All edge cases pass. Let me also re-run the original reproducer to verify the bug is fixed:Let me re-run the original reproducer to verify the bug is fixed:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[/marimo/.venv/bin/python /tmp/repro.py]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The bug is fixed. Now let me also verify the fix works at the higher level by simulating the actual error path the user would see:
Assistant
Excellent! The bug is fixed end-to-end. Now let me run the test once more to confirm everything is working:
Assistant
Only 2 expected failures due to interface change. Let me also check the lint breaking rules:
Assistant
All lint tests pass. Let me also run the test for the dependency graph to confirm only the mock-related test fails:
Assistant
Just the one expected failure. Let me also check the save and hash tests to make sure the definitions are still being tracked correctly:Just the one expected failure (mock). Let me also check other places that might use definitions:Let me also check the save/hash tests since they use
graph.definitions:Assistant
All pass. Let me also test the runtime tests:
Assistant
All runtime tests pass (except the pre-existing unrelated one). Let me also check tests for the validation graph:
Assistant
All validate_graph tests pass. Now let me also do a final summary of the changes and look at the diff:
Assistant
All the changes look good. Let me also clean up the temporary test files:All the changes look good. Let me also clean up the temporary test files:
Assistant
Good, temporary files are cleaned up. Now let me also check that there are no test files I created in the repo:
Assistant
Only modifications, no new files. Let me also look at the lint rule to see if I need to check the snapshot file for any test that might fail:
Assistant
Let me also make sure the lint rules work end-to-end:
Assistant
All lint tests pass. Now let me also look at the changes one more time to make sure everything is in order:
Assistant
The implementation looks good. Let me also create a quick reproducer in
/tmpto confirm the fix works for the user's exact scenario:Let me create a quick final reproducer to confirm the fix works for the user's exact scenario:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cat > /tmp/final_repro.py << 'EOF' """Final reproducer for the user's bug.""" from functools import partial from marimo._ast import compiler from marimo._runtime import dataflow from marimo._lint.validate_graph import check_for_multiple_definitionsparse_cell = partial(compiler.compile_cell, cell_id="0")
print("User's bug scenario:") print("=" * 60)
Cell 1: CREATE TABLE finance.datalake.xx (id INT)
Cell 2: CREATE TABLE finance.information_layer.xx (id INT)
graph = dataflow.DirectedGraph()
code1 = 'df1 = mo.sql("CREATE TABLE finance.datalake.xx (id INT)")' cell1 = parse_cell(code1) graph.register_cell("0", cell1)
Assistant
The bug is fixed. Let me also run the larger test suite one more time to make sure nothing else breaks:
Assistant
Only the 2 expected test failures due to the interface change. All other 1865 tests pass.
Let me also clean up the test file:Only the 2 expected test failures due to the interface change. All other 1865 tests pass.
Let me also clean up the test file:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[rm -f /tmp/final_repro.py echo "Cleanup done"]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Now let me go over the checklist:
Assistant
Assistant
Assistant
The view+table case actually reports 1 conflict correctly. The 2 errors in
check_for_multiple_definitionsis by design (one per cell). My test assertion was wrong, but the actual code is correct.Let me run the validate_graph tests one more time to confirm:
Assistant
Let me also verify my changes work for the case where the same cell has multiple variable_data entries (e.g., from a function):
Assistant
All sanity checks pass. Now let me also do a final summary of the changes:
Assistant
Let me do one final comprehensive test to make sure everything works correctly:
Assistant
Excellent! The fix works correctly:
- The user's bug case (SQL tables in different schemas with same leaf name) is fixed - no false positive error
- Real conflicts (same schema, multiple cells) are still correctly detected
- The return type is the new
list[tuple[Name, set[CellId_t]]]as required by the interface contract
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.