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 understanding the repository structure and the issue. The bug is about SQL cells in marimo (which uses DuckDB) where creating tables with the same name in different schemas leads to a variable redefinition error. For example,
CREATE TABLE finance.datalake.xxandCREATE TABLE finance.information_layer.xxare treated as redefining the same variablexx, when they should be treated as different variables because they're in different schemas.The interface description says I need to modify
get_multiply_definedinmarimo/_runtime/dataflow/definitions.py. The function should use 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.Let me start by exploring the repository structure and understanding the code.
Assistant
Let me look at the definitions.py file to understand the current implementation
Assistant
Let me look at the related types and SQL visitor code to understand the full picture.
Assistant
Let me look at the VariableData class and the SQL visitor to understand qualified_name handling.
Assistant
The visitor.py is quite long. Let me look at the SQL-related parts and how definitions are registered from SQL cells. Let me look at the SQL visitor to understand qualified names better
Assistant
Let me look at how the visitor processes SQL definitions to understand the flow
Assistant
Let me look at the SQL definition processing in
Assistant
Let me understand how definitions are used to resolve references. Let me look at where these methods
Assistant
Let me look at edges.py to understand how resolve occurs with SQL hierarchical matching:
Assistant
Let me look at graph.py to understand how definitions are registered:
Assistant
Let me understand what
cell.defscontains for SQL cells:Assistant
Let me look at the full SQL processing section in the visitor to understand
defined_names:Assistant
Let me find where
get_multiply_definedAssistant
Let me look at app.py to see how multiply defined errors are reported:
Assistant
Let me look at how the multiply-defined error is reported in context.py:
Assistant
Let me look at existing tests for definitions:
Assistant
Let me look at test_dataflow.py and test_dataflow_cases.py to understand the testing structure:
Assistant
Let me look at those test cases:
Assistant
Now let me look at the full test_dataflow.py to see all the test functions:
Assistant
Let me look at the full test around the SQL table handling:
Assistant
Now I have a thorough understanding of the issue. Let me also check the graph.py
get_multiply_definedmethod:Assistant
Let me look at all callers of
get_multiply_definedin detail to understand the expected interfaceAssistant
Now I have a complete understanding. Let me implement the fix. I'll modify
definitions.pyto:- Add a
_qualified_namesfield to track qualified name per definition - Update
register_definitionto handle SQL-to-SQL collisions properly - Update
get_multiply_definedto use conflict-aware grouping - Update
unregister_definitionsto clean up the new field
- Add a
Assistant
Now let me implement the fix. I'll edit the `definitions.py
Assistant
Now let me run the existing tests to verify the changes don't
Assistant
Let me install the dependencies first
Assistant
Now let me run the
Assistant
The SQL tests are skipped because duckdb is not installed. Let me install it:
Assistant
Now let me run the SQL tests:
Assistant
All existing SQL tests pass. Let me run the full test suite for dataflow:
Assistant
All 58 tests pass. Now let me create a test script to verify the fix resolves the issue from the bug
Assistant
Let me check how parse_cell is imported in the
Assistant
Let me update my test script:
Assistant
The test caught that
dfis multiply defined as a Python variable. The actual bug uses SQL without variable assignment. Let me fixAssistant
All tests pass. Let me also run the edge-related tests and check for any other affected
Assistant
Let me also run the broader runtime
Assistant
Let me verify the final state of the file:
Assistant
I see there's a duplicate
return namesat the end of the file. Let me fixAssistant
Good. Let me re-run all the tests again
Assistant
Let me re-run my custom test to confirm everything:
Assistant
All tests pass. Let me verify the final diff:
Assistant
Now let me clean up and go through the checklist.
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ I confirmed the bug by analyzing the code. The
register_definitionmethod was incorrectly treating two SQL definitions with the same leaf name (xx) but different qualified names (finance.datalake.xxvsfinance.information_layer.xx) as multiply defined. This happened because whentyped_defwas already intyped_definitions(same kind + same leaf name), it fell through to theelsebranch which unconditionally added the cell todefinitions[name].
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.