🐛 Bug ❓: Variable name collision for SQL cells using same table name in different…
- User
🐛 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
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.
- Assistant
Now let me look at how
qualified_nameis computed for created tables, and the callers I'll need to update. - Assistant
Now let me check existing tests around typed definitions and views to avoid regressions:
- Assistant
Now I have the full picture. Let me implement the changes, starting with the core registry:
- Assistant
Now update the graph delegating method:
- Assistant
Now the other callers. First
app.py: - Assistant
Now update the tests. First the mock in the AI tools test:
- Assistant
Now update the dataflow tests and add regression tests for the bug:
- Assistant
Add validate_graph tests for the SQL case:
- Assistant
The mypy errors are all in unrelated files (plotly, pandas_table, AI providers — pre-existing), and the final
makefailure is a missingpixibinary in this environment. Let me verify my changed files are clean: - Assistant
Pre-existing on HEAD, so not from my changes. Now the format check that got short-circuited:
- Assistant
While that runs, double-check nothing else consumes the old return shape:
- Assistant
The core diff looks right. Waiting on the full runtime suite now — let me check its progress:
- Assistant
The suite is still running; I'll wait for its completion notification.
- Assistant
While waiting, let me double-check that the
Nameimport is still needed ingraph.pyand review the validate_graph diff once more: - Assistant
Diffs look good. Now I'll wait for the runtime suite to finish.
- Assistant
Waiting on the full
tests/_runtimesuite (background task) — I'll report as soon as it completes. - Assistant
The full runtime suite is still executing in the background. I'll summarize the work so far and report the final test result when the suite completes.
What was changed (fix for the schema-qualified SQL table collision bug):
-
marimo/_runtime/dataflow/definitions.py—DefinitionRegistrynow tracks each definition's qualified identity:- New
qualified_definitions: dict[Name, dict[Name, set[CellId_t]]]groups defining cells by fully qualified name (finance.datalake.xx), falling back to the plain name for Python variables and unqualified SQL names.
- New
-
- Assistant
Confirmed — those 3 failures also occur on clean HEAD (pre-existing, unrelated to this change). The fix is complete and verified.
Summary
Bug: Two SQL cells creating tables with the same leaf name in different schemas ( and ) raised a "This cell redefines variables from other cells" error, even though the fully qualified names are distinct and valid in DuckDB.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.