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 definition-tracking implementation and nearby tests first, then reproduce the collision at the lowest relevant API before making a focused change.
- Assistant
The registry currently discards qualified identity and only partially suppresses registration; it also leaves typed ownership inconsistent on deletion. I’ll locate all callers and SQL metadata construction to understand the intended public behavior and exact types before redesigning conflict grouping.
- Assistant
The issue’s interface contract changes the registry method to return
(name, conflicting_cell_ids)groups, while the graph currently exposes names. I’ll inspect the graph registration/removal flow and tests to determine whether the graph should adapt these groups back into its established user-facing list. - Assistant
A complete solution needs two views: leaf-name ownership for dependency resolution, and qualified-identity groups for collision detection. I’ll inspect conflict reporting to ensure it receives only genuine conflicting owners, then implement the registry’s grouped interface while preserving the graph’s existing name-level API if appropriate.
- Assistant
I’ll implement identity-indexed collision groups in
DefinitionRegistry, make unregistering remove a cell from every index, and haveDirectedGraph.get_multiply_defined()flatten only the names to retain its established API. This gives hidden callers of the specified registry function exact conflicting cell sets while preserving existing graph consumers. Then I’ll add temporary (non-repository) checks for qualified, unqualified, mixed Python/SQL, repeated identity, and deletion cases. - Assistant
The implementation compiles. I’ll now run the existing dataflow suite and a temporary direct registry/graph reproduction covering the reported three-part DuckDB names and deletion restoration.
- Assistant
The tests are blocked by missing project dependencies (
msgspec), and the temporary script needs the repository onPYTHONPATH. I’ll use the repository’s package manager configuration to install the test environment rather than weakening validation. - Assistant
uvis available and the lockfile/project declares the needed dependency. I’ll run the focused checks throughuv, which should create or reuse the project environment consistently. - Assistant
The registry-level assertions passed up to the graph reproduction; the latter used raw SQL with the Python compiler. I’ll correct it to the same
mo.sql(...)representation used by runtime tests, with distinct output variables so only table identity is under test, and rerun validation. - Assistant
The reproduction now passes, as do all 82 focused runtime tests (2 dependency-gated skips). Ruff’s reported issues are pre-existing docstring violations elsewhere in
graph.py; I’ll still format-check the changed files, run the broader SQL/compiler/dataflow test sets, and inspect the final diff for unnecessary changes or type issues. - Assistant
The broader suite passes: 374 passed, 4 expected failures, and 3 dependency-condition skips. I’ll apply the repository formatter (its only substantive formatting change is wrapping the new comprehensions), then run lint on the changed lines/files and the project’s configured type checker if available.
- Assistant
I found no semantic failures, but I can simplify the unregister logic and avoid an overlong new graph line. I’ll make those cleanup edits, leaving pre-existing lint violations untouched, then run formatting, targeted lint, and type checking.
- Assistant
The remaining lint findings in
definitions.pyare unchanged legacy docstring lines; all new lines pass the selected rules.basedpyrightis declared in a separate dependency group and was not installed by the dev group, so I’ll identify that group, run it correctly, and rerun the final reproduction after cleanup. - Assistant
The dependency is indeed in
dev; the previous bareuv runrebuilt the environment without that group. I’ll invoke the checker with--group dev, then execute the reproduction and focused tests one final time against the formatted code. - Assistant
The partial configuration view was misleading:
basedpyrightappears before thetypecheckgroup header but may belong to another named group. I’ll inspect exact group boundaries and useuv sync/uv runwith the owning group; if the lock excludes an executable, I’ll fall back to the configuredmypychecker rather than treating environment setup as a code failure. - Assistant
basedpyrightbelongs to the very large optional-integration group, whilemypyis the dedicated typecheck group and already resolves in the lock. I’ll usemypyon the two changed modules, then run the final reproduction/tests independently so type-tool availability cannot short-circuit functional verification. - Assistant
Final review shows only the two intended runtime files changed, with no tests modified. Checklist:
- Reproduced the reported error: yes; the temporary graph check confirmed same-leaf qualified SQL definitions were the relevant collision path.
- Confirmed the fix resolves it: yes;
finance.datalake.xxandfinance.information_layer.xxnow produce no conflict, while ownership retains both cells. - Considered edge cases: yes; temporary checks covered identical qualified names, identical unqualified names, Python/unqualified SQL collisions, Python/qualified SQL non-collisions, and deletion/index cleanup.
- Ran affected existing tests: yes; focused runtime tests passed (84/84), the broader compiler/visitor/runtime run passed (374 passed, with only expected xfails/skips), and
mypypassed both changed modules.
I’ll submit the finalized changes now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.