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 SQL visitor to understand how qualified names work.
Assistant
Now let me look at the visitor to understand how variables are tracked and what
qualified_nameis:Assistant
Now let me look at the graph.py to see how
get_multiply_definedis used:Assistant
Now let me check how
definitions.pyis being tested and used:Assistant
Now let me look at the existing tests for the DefinitionRegistry:
Assistant
Now let me look at the SQL visitor section for
qualified_nameto understand what the values are like for fully qualified SQL names:Assistant
Let me check how
find_sql_hierarchical_matchesis being used:Assistant
Now let me understand the bug clearly by reading more of
register_definition:Assistant
Let me check the rest of the existing tests:
Assistant
Let me check how the return value of
register_definitionis used:Assistant
OK so the return value of
register_definitionis currently discarded. Let me verify thisAssistant
Let me also check what's done in
unregister_definitions:Assistant
Now let me write a script to reproduce the bug first:
Assistant
I've successfully reproduced the bug. Now let me look at the test files to understand the existing test patterns:
Assistant
Let me look at how
definitionsanddefinition_typesare used elsewhere:Assistant
Let me look at the existing tests more carefully to understand the semantics:
Assistant
Let me test what happens with SQL first then Python:
Assistant
Let me check if there are any tests that test this specific case:
Assistant
Let me check how
definitionsis used in edge computation:Assistant
Now I understand the architecture. Let me design the fix and implement it:
Assistant
Now let me implement the fix:
Assistant
Now let me run the reproduction script:
Assistant
The bug is fixed. Now let me write more comprehensive tests to verify edge cases:
Assistant
All cases pass. Now let me run the existing tests to see what passes and what doesn't:
Assistant
expected, the existing test fails because the return type changed. Per the instructions, we ignore tests that break due to API changes. Let me run the rest of the tests:
Assistant
a bug in my
unregister_definitions- I'm modifying the dict while iterating. Let me fix it:Assistant
Let me retry the replacement. The file is showing me the lines so now I can use the edit command directly
Assistant
Let me simplify the unregister_definitions function:
Assistant
Now let me re-run the tests:
Assistant
All other tests pass. The 2 failures are expected (API change). Let me also run other tests that might be affected:
Assistant
Let me update the type hint in graph.py to match the new return type:
Assistant
Now let me look at how
get_multiply_definedis used elsewhere to make sure we don't break callers:Assistant
Let me check the callers that use
get_multiply_defined()to understand what they expect:Assistant
Let me check each caller of
get_multiply_defined()to see how they use it:Assistant
need to update all callers to handle the new return type. Let me update them:
Assistant
Now let me update the
_code_mode/_context.py:Assistant
Now let me update
marimo/_convert/ipynb/to_ir.py:Assistant
Now let me update
marimo/_ai/_tools/tools/dependency_graph.py:Assistant
Now let me run the related tests to ensure I haven't broken anything:
Assistant
me verify the actual fix works in practice:
Assistant
All edge cases pass. Now let me make the test_dependency_graph.py work correctly without modifying the test by handling the mock properly. Let me check the test setup more carefully:
Assistant
me verify all callers are updated correctly:
Assistant
Good, all imports work. Now let me run the relevant test suites to see the impact:
Assistant
Let me verify the unrelated failure is pre-existing:
Assistant
Confirmed, the
test_non_windows_does_not_change_event_loop_policyfailure is unrelated to my changes (it's a permission issue withos.setsid()).Let me restore my changes:
Assistant
All 3 failures are expected API changes. Let me look at the full implementation once more to verify it's clean:
Assistant
Let me also think about edge cases more carefully. Let me test a few more scenarios:
Assistant
All edge cases pass. Now let me also verify deletion behavior works correctly:
Assistant
Deletion works correctly. Let me also test re-registration after deletion:
Assistant
Let me also check if there are any tests in test_runtime.py that test multiply_defined:
Assistant
Let me check the lint rules and see if they have the same issue:
Assistant
Let me update the
check_for_multiple_definitionsfunction to be consistent with the new conflict-aware logic:Assistant
Now let me also check the runtime.py for how the multiply_defined is processed:
Assistant
Good, I've already updated all the relevant places. Let me also check the kernel level processing:
Assistant
Let me run a broader test suite to make sure I haven't broken anything else:
Assistant
The snapshot test fails because my change altered the snapshot output. Let me look at what the test expects and see if it's a snapshot of
check_for_multiple_definitionsor something else.Assistant
This is a snapshot test failure. The diff shows that the order of errors changed. Looking at the output, it's just changing the order of error reporting (b before c, instead of c before b).
The test failure is just because the snapshot expects a specific order. The reason for the order change is that my updated
check_for_multiple_definitionsusesgraph.get_multiply_defined()which iterates in dict insertion order, while the original iterated which sorted by name.Assistant
The snapshot was auto-updated when the test ran. Let me revert this since I shouldn't modify tests. The order difference is just an artifact of dict insertion order vs sorted order:
Assistant
Let me make the validation function preserve the sorted order to match the original behavior:
Assistant
All snapshot tests pass now. Let me also run all the lint tests:
Assistant
All lint tests pass. Let me run all the runtime tests:
Assistant
Let me run additional test suites that could be affected by my changes:
Assistant
Let me check what's failing in the code_mode tests:
Assistant
me verify this is pre-existing:
Assistant
TestPackages failures are pre-existing. Let me verify the
test_multiply_defined_variablesfailure is from API change:Assistant
Let me run the reproduction script once more and the edge cases to confirm everything works:
Assistant
All my custom tests pass. Let me also make sure the original behavior of the existing tests is preserved:
Assistant
All SQL tests pass except the 2 that were directly affected by the API change. Let me now do a final review of the code:
Assistant
me do a final comprehensive test:
Assistant
the 2 expected failures. Let me also run the
_aitests to confirm:Assistant
The only AI test failure is the mock inconsistency due to API change. This is expected.
Now let me also clean up my temporary test files:Let me also clean up temporary test files:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[rm -f /tmp/reproduce_bug.py /tmp/reproduce_bug2.py /tmp/test_edge_cases.py /tmp/test_more_edge_cases.py /tmp/test_deletion.py /tmp/test_reregister.py /tmp/edit_unregister.py /tmp/edit_app.py /tmp/edit_context.py /tmp/edit_ir.py /tmp/edit_dep_graph.py /tmp/edit_graph.py /tmp/edit_validate.py /tmp/edit_validate2.py]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Now let me also run one more test to make sure my reproduction works:
Assistant
Let me look at the issue example more carefully - both cells use
dfas the Python variable name which is itself a conflict:Assistant
The bug is correctly fixed. Let me clean up:
Assistant
Let me also do a quick check that all the lint and tests still pass:
Assistant
Only the 2 expected API change failures remain. Let me do a final review of all my changes:
Assistant
Let me now run my final reproduction one more time to confirm everything is fixed:
Assistant
All my tests pass. Let me do a final summary of the changes:
Assistant
Let me review my checklist before submitting:
Checklist Review:
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ YES - I reproduced the bug with the exact example from the issue using
CREATE TABLE finance.datalake.xxandCREATE TABLE finance.information_layer.xx. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ YES - My reproduction script now shows
multiply_defined = [](empty) for the issue's example, confirming the fix. -
I have thought about edge cases and made sure my fix handles them as well. ✅ YES - I tested many edge cases:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.