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
I’ll inspect the definitions implementation and its tests, trace how SQL names are represented, then implement conflict-aware grouping while preserving the existing public behavior for true collisions. I’ll run focused tests and broader relevant tests before submitting.
- Assistant
The current registry stores all SQL definitions under the leaf name, but
get_multiply_definedcannot distinguish their qualified identities. I’ll retain the leaf-keyed registry (so ownership, references, and deletion remain intact), add per-cell qualified identity metadata, and make multiply-defined reporting group cells by that identity. Because the stated interface returns(name, cell_ids)tuples, I’ll update internal consumers to extract names while retaining the cell sets for the API. - Assistant
The focused test command is currently blocked before collection because the environment lacks the repository dependency
msgspec; compilation of all changed modules succeeds. I’ll now audit every call site for tuple handling, run a dependency-free direct registry check, and inspect the diff for lifecycle and compatibility issues. - Assistant
The direct registry check confirms the key cases: different qualified names do not collide, identical qualified names do, and unregistering a defining cell clears the conflict. I’m preserving the existing
DirectedGraphstring-list API for compatibility; the requested tuple interface is specifically onDefinitionRegistry.get_multiply_defined, and the graph will project those tuples back to names for existing callers. - Assistant
Implemented the SQL definition collision fix.
Summary:
- Added per-cell qualified SQL identity tracking in
DefinitionRegistry. - Updated
DefinitionRegistry.get_multiply_defined()to return(name, cell_ids)tuples grouped by complete qualified identity. - Tables with the same leaf name in different schemas/catalogs no longer conflict.
- Identical fully qualified names still report conflicts.
- Unqualified duplicate names still report conflicts.
- Preserved the existing
DirectedGraph.get_multiply_defined()string-list API. - Preserved definition ownership and cleanup behavior during deletion.
Verification:
- Direct registry checks passed for:
- Different schemas not colliding.
- Same qualified table name colliding.
- Unqualified names colliding.
- Deletion clearing conflicts.
- Changed modules compile successfully.
git diff --checkpassed.- Focused pytest execution was blocked because the environment lacks the
msgspecdependency.
- Added per-cell qualified SQL identity tracking in
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.