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
sql-- Cell 1 CREATE TABLE finance.datalake.xx (id INT);sql-- Cell 2 CREATE TABLE finance.information_layer.xx (id INT);ERROR
codeThis 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
coderequires-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
- Assistant
I'll start by exploring the repository structure and locating how SQL definitions and multiply-defined variables are tracked.
- Assistant
Looking at the definitions module and how SQL table names are tracked.
- Assistant
Let me read the rest of the file and search for related code.
- Assistant
I'll inspect related graph/edge code and existing tests to see how definitions and conflicts are handled.
- Assistant
Let me look at the test for get_multiply_defined and the register_definition logic more carefully. Also, let me look at edges.py for how siblings work.
- Assistant
I'll inspect how multiple definitions are validated and how cells register definitions.
- Assistant
Inspecting how SQL defs and qualified names are stored on cells:
- Assistant
Checking recent history and how callers use
get_multiply_defined: - Assistant
I'll check if there's prior work or tests for this exact multi-schema case, and inspect how
definitionsis used. - Assistant
Checking whether the siblings return value is used and reviewing graph-related definitions more closely.
- Assistant
DefinitionRegistry needs qualified-identity tracking so conflict detection can work without name collisions. Exploring storage options next.
- Assistant
Reproducing the bug, then implementing qualified-identity tracking for conflict-aware multiply-defined detection.
- Assistant
Implementing the fix in
definitions.pyand updating related callers. - Assistant
Let me write the full new definitions.py file.
- Assistant
Updating the graph method and its callers next.
- Assistant
Updating remaining callers of
get_multiply_defined. - Assistant
The replace tool needs the target regions open; opening each file and applying the edits.
- Assistant
Continue with other files.
- Assistant
Continue with dependency_graph and code_mode.
- Assistant
Now update code_mode.
- Assistant
Need to fix the new_multiply_defined part too.
- Assistant
Improving the code_mode error path so it reports only true collidees:
- Assistant
Verifying the fix against the original bug and related edge cases:
- Assistant
Running related existing tests:
- Assistant
Making multiply-defined results sorted for stable output and reverting any auto-updated snapshots.
- Assistant
Sorting multiply-defined results by name for deterministic error ordering.
- Assistant
Re-running related tests after the sort fix:
- Assistant
Checking whether package test failures are pre-existing and inspecting the dependency graph test:
- Assistant
Checking the lint snapshot and more targeted tests:
- Assistant
Lint snapshot passes now. The two remaining failures are just interface return type changes - expected and can be ignored.
- Assistant
Running a few more related tests to make sure nothing else is broken:
- Assistant
Reviewing the final diff:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.