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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /marimo, current file: none) bash-$
Assistant
Let me start by understanding the repository structure and the issue. The problem is about SQL cells in marimo with DuckDB where tables with the same name but in different schemas are considered as variable name collisions. The fix should be in
marimo/_runtime/dataflow/definitions.py, specifically in theget_multiply_definedmethod.Let me first explore the repository structure and find the relevant file
Assistant
Let me find the specific file mentioned in the issue.
Assistant
Let me open and examine this file.
Assistant
Let me see the rest of the file
Assistant
Let me understand the SQL visitor and VariableData structure to see how qualified names are
Assistant
Let me also look at the VariableData definition.
Assistant
Let me look at the VariableData class.
Assistant
Let me open the file properly.
Assistant
Now let me look at the SQL visitor to understand how qualified names
Assistant
Let me search for where
qualified_nameis set in the SQL visitor.Assistant
Let me look around line
Assistant
Let me just view that area.
Assistant
Let me find where SQL CREATE TABLE/VIEW definitions are registered in the visitor.
Assistant
Let me look at the SQL definition registration in the visitor more
Assistant
Let me look at the
_definemethod and how definitions flow into the registry.Assistant
Let me find how
register_definitionis called and how cell definitions are collectedAssistant
Let me look at how register_definition is called in graph.py
Assistant
Let me look at how
get_defining_cellsandget_multiply_definedare usedAssistant
Let me look at the graph.py code and the key usage sites
Assistant
Let me just open graph.py at the right line.
Assistant
Let me look at the code_mode context code where multiply_defined is
Assistant
Let me look at the app.py code
Assistant
Let me find the tests for the definitions module
Assistant
Let me look at the edges.py to understand how SQL definitions are
Assistant
Let me just view the edges.py relevant sections.
Assistant
Let me understand all callers of
get_multiply_definedand their expectationsAssistant
Now I have a thorough understanding of the issue. Let me now implement the fix. The strategy:
- Add a
_conflict_groupsfield to track qualified names for conflict detection - Update
register_definitionto populate it - Update
unregister_definitionsto clean it up - Update
get_multiply_definedto use conflict-aware grouping
Let me write
- Add a
Assistant
Now let me implement the fix. I'll edit the
DefinitionRegistryclassAssistant
Let me verify the full
Assistant
Let me check how
cell.defsis set to understand what names are passed tounregister_definitions.Assistant
Let me find how cell.defs is populated
Assistant
Let me search more broadly
Assistant
Let me find CellImpl
Assistant
Let me look at CellImpl's defs attribute
Assistant
Let me find where CellImpl is instantiated and defs is set
Assistant
Let me look at the compiler code where defs is set
Assistant
Let me find how nonlocals is populated
Assistant
Let me check the visitor's def
Assistant
Now let me run the existing tests related to definitions and multiply-defined to make sure I haven't broken anything.
Assistant
Let me write a small test script to validate my changes and run it directly
Assistant
Let me try running the test differently by avoiding the full marimo import chain
Assistant
Let me install the missing dependency
Assistant
Now let me try running the test again
Assistant
Let me try a different approach to test - use
-cwith specific path manipulation to avoid the fullAssistant
Let me install the required dependencies
Assistant
Now let me run the
Assistant
All tests pass. Now let me run the existing test suite for the relevant
Assistant
Let me run a broader test to check for breakage - looking for test files related to graph, definitions, or app
Assistant
Let me check the specific failing
Assistant
That's a test environment issue (missing async plugin). Let me run tests that are more relevant to definitions and multiply-defined
Assistant
Let me check if these failures are pre-existing by reverting my change
Assistant
Same results - pre-existing failures. Let me restore my changes
Assistant
Let me find and run tests specifically related to multiple
Assistant
Let me run the app tests specifically related to multiply defined variables
Assistant
Let me look at this
Assistant
Let me check if this test was already failing before my changes
Assistant
Pre-existing failure. Let me run the passing multiply/redefin
Assistant
The 4 non-async tests pass. Let me look at
test_multiple_definitionsto understand what it testsAssistant
Let me also check the convert tests
Assistant
All convert tests pass. Let me also check the lint
Assistant
Let me check if those failures are
Assistant
Let me check the failing lint
Assistant
Let me look at the test_multiple_definitions
Assistant
Let me look at these
Assistant
Let me check for SQL-specific tests related to definitions
Assistant
Let me look at the dataflow tests
Assistant
Let me see the full context
Assistant
Let me run the dataflow tests to make sure they
Assistant
Let me see the full output
Assistant
Let me improve the
unregister_definitionsto ensure_qualified_defsis always cleaned up, even when a name is not inself.definitions(edge case for SQL with qualified names)Assistant
I see there's duplicate code. Let me view the full file to
Assistant
I see the duplicate. Let me fix the
Assistant
Good, the file is now clean. Let me rerun the tests to verify everything
Assistant
All tests pass. Let me also run the existing test suite one
Assistant
Let me run the graph validation
Assistant
All graph validation tests pass. Let me now verify the final file is correct
Assistant
Let me run one final comprehensive set of tests to validate
Assistant
Let me verify the two failures are pre-existing
Assistant
Both failures are pre-existing. Let me verify my
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →