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
Let me explore the marimo directory and look at the file mentioned in the issue.
Assistant
me explore the broader context to understand how SQL variables work.
Assistant
me look at how DefinitionRegistry is used elsewhere.
Assistant
me look at the existing tests for definitions.
Assistant
Let me check existing SQL tests and reproduce the issue.
Assistant
Let me check how SQL refs are resolved.
Assistant
Let me look at where
register_definitionis called and what its return value is used for.Assistant
Let me check how
definitionsis used throughout the codebase.Assistant
Let me check how
get_multiply_definedis used inapp.py.Assistant
Let me look at the existing tests more carefully to understand the desired behavior.
Assistant
Let me check what the qualified_name looks like for unqualified SQL.
Assistant
Let me look at the callers of get_multiply_defined.
Assistant
Let me search for tests related to multiply defined and SQL.
Assistant
me look at the test_dataflow tests that use get_multiply_defined.
Assistant
Now let me look at all the tests that exist for definitions to understand the contract better.
Assistant
Let me see the test_sql_table_schema_to_python_ref_rev test.
Assistant
I have a clear understanding. Let me implement the fix.
Assistant
Let me also check the case without the
df =.Assistant
understand the bug. Let me write the fix.
Assistant
let me test the fix with my reproduce script.
Assistant
bug is fixed. Now let me check that the existing tests pass and identify which ones break.
Assistant
failing tests are due to the interface change, not bugs in my fix. Let me run more tests.
Assistant
me check the specific multiply_defined related test failures.
Assistant
I need to update the callers to handle the new return type. Let me find and update them.
Assistant
Now let me update each caller to handle the new return type.
Assistant
Let me update the dependency_graph.py to handle the new return type.
Assistant
let me update
_code_mode/_context.py.Assistant
let me update the ipynb converter.
Assistant
run the tests to see if my fixes work.
Assistant
The remaining failures are due to the interface change. These tests check the exact return value of
get_multiply_defined()which has now changed fromlist[Name]tolist[tuple[Name, set[CellId_t]]].According to the instructions, I should not modify existing tests. The contract specifies the new return type, so these tests will need to be updated to match the new contract.
Let me also run the dependency_graph test and ipynb test to see if my updates worked
Assistant
Let me check the dependency_graph test setup more carefully and see if my code can be more robust.
Assistant
Let me update the dependency_graph.py to maintain backward compat with the test.
Assistant
Let me make the dependency_graph.py robust to handle both formats.
Assistant
Now let me run all the related tests to see what's left failing.
Assistant
Let me confirm those TestPackages failures are pre-existing and unrelated to my fix.
Assistant
TestPackages failures are pre-existing and unrelated. Let me check the ipynb tests.
Assistant
Now let me test more edge cases with my fix.
Assistant
edge cases pass. Let me also test deletion scenarios.
Assistant
deletion tests pass. Let me verify re-registration works too.
Assistant
a bug in re-registration. Let me debug.
Assistant
Actually my test was wrong. Let me verify the behavior is correct - cell 0 and cell 1 with different schemas shouldn't conflict.
Assistant
behavior is correct. Let me run the full dataflow tests one more time to make sure everything is working.
Assistant
2 remaining failures are due to the interface change, which is expected per the contract. Let me run a broader set of tests to ensure nothing else is broken.
Assistant
failure is unrelated to my fix (PermissionError on
os.setsid()). Let me confirm.Assistant
test failure is pre-existing and unrelated. Let me run more tests.
Assistant
All AI tests pass. Let me also check the code mode
Assistant
Let me run more comprehensive tests including my custom ones.
Assistant
me verify my final code looks good.
Assistant
check all my changes.
Assistant
me run a broader test to verify nothing important is broken.
Assistant
Out of 13 failures:
- 2 are due to interface change (test_sql_table_schema_to_python_ref, test_sql_table_schema_to_python_ref_rev) - acceptable
- 1 is unrelated (test_non_windows_does_not_change_event_loop_policy - permission error)
- 10 are unrelated (TestPackages - package installation issues)
Let me confirm the TestPackages failures are pre-existing
Assistant
TestPackages failures are pre-existing. Let me also check a few more critical tests.
Assistant
me also run a final comprehensive test to ensure my fix is complete.
Assistant
All tests pass. Let me also clean up my temporary files and do a final review.
Assistant
Let me also check the graph.py diff to make sure my changes there are right:
Assistant
Let me check the convert/ipynb/to_ir.py and _code_mode/_context.py diff
Assistant
All my changes look good. Let me verify the final state of definitions.py one more time and run a final test.Let me do a final verification.]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /marimo && cat > /tmp/verify_final.py << 'EOF' """Final verification of the bug fix.""" from functools import partial from marimo._ast import compiler from marimo._runtime import dataflow
parse_cell = partial(compiler.compile_cell, cell_id='0')
The exact bug case from the issue
print("=" * 60) print("Bug case from issue: Same table name, different schemas") print("=" * 60)
Assistant
Let me re-run the command
Assistant
error is just about type hints resolution, not functionality. Let me simplify.
Assistant
All verifications pass. Let me clean up the temporary file and finalize.
Assistant
Let me verify the checklist:
-
Bug reproduced: Yes, I reproduced the bug at the start with
_ = mo.sql(...)cells showingmultiply_defined: ['xx']when it should be[]. -
Bug fixed: Yes, the bug is fixed - the same cells now produce
multiply_defined: []. -
Edge cases handled: I tested multiple edge cases:
- Different schemas (bug case) → no conflict ✓
- Same qualified name → conflict ✓
- Unqualified SQL + Python → conflict ✓
-
Assistant
The fix is complete. Let me submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.