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 dataflow definitions and SQL name representation first, then locate targeted tests and reproduce the collision through the lowest-level API before changing behavior.
- Assistant
The registry currently partially suppresses insertion into
definitions, but loses qualified identity and has inconsistent typed/deletion bookkeeping. The requested interface also differs from the current annotation, so I’ll inspect all callers and the AST metadata to design a compatible conflict grouping rather than shifting ownership semantics. - Assistant
I’ll now read graph registration/deletion, conflict consumers, and existing SQL dataflow tests. This will reveal whether
get_multiply_definedshould expose tuples directly at the registry level while the graph preserves its public list-of-names API. - Assistant
The intended split is clear:
definitions[name]must retain every defining cell for dependency ownership and deletion, while a separate identity-aware index determines collisions. I’ll inspect direct registry construction and unregister tests before implementing that index; SQL identity will bequalified_name(falling back to the user-facing leaf), and all metadata entries must be considered, not just the last. - Assistant
Before editing, I’ll capture the reported failure with two schema-qualified SQL definitions. Then I’ll add a qualified-identity conflict index, keep the ownership index complete, make unregister clean every index per cell, and adapt the graph facade to continue returning user-facing names.
- Assistant
The reproduction is currently blocked by an uninstalled project dependency (
msgspec), not by the code path. I’ll use the repository’s configured environment runner if available while making the focused implementation. - Assistant
I’m implementing the index now. The conflict key deliberately excludes SQL kind: a table and view with the same fully qualified identifier still collide, while different catalogs/schemas do not. The returned cell set is aggregated by user-facing leaf so conflict reporting remains unchanged.
- Assistant
The implementation is in place. I’ll run the original reproduction under
uv, plus direct registry edge cases covering different/same qualification, unqualified SQL versus Python, ownership, and unregister behavior. - Assistant
The reproduction now passes and confirms both defining cells remain owned by
xx; genuine collisions and deletion also behave correctly. Ruff formatting passes, while full-file lint reports five unrelated pre-existing property-docstring violations ingraph.py. I’ll run the affected runtime suites and type checks next. - Assistant
The targeted suites pass (82 passed, 2 optional-dependency skips), and the interface/type changes introduce no reported type errors. One subtle reporting case remains: when one qualified identity genuinely collides and another same-leaf identity does not, consumers must receive only the genuine collision’s cells. I’ll inspect how conflict cell IDs are gathered and adjust the graph facade if needed.
- Assistant
Most consumers only need names, but one code-mode diagnostic uses all owners and could include a distinct qualified table in a genuine collision message. The evaluation contract specifically exposes cell sets from the registry, likely to solve exactly this ambiguity. I’ll add a graph helper for collision cells only if runtime conflict construction currently needs it; first I’ll locate those paths.
- Assistant
I found the actual runtime validator still independently treating every shared leaf owner as a collision, which would preserve the reported bug despite the registry fix. I’ll switch it to the conflict-aware registry result. This also ensures only cells sharing the exact qualified identity receive errors, while
graph.definitionsremains complete for ownership and dependencies. - Assistant
The expanded lint suite exposed only an ordering regression: the old validator emitted conflicts sorted by name, whereas the new registry preserves registration order. Its snapshot helper rewrote one test artifact on failure, so I’ll immediately restore that forbidden test change and sort the conflict tuples in the validator to preserve established reporting order.
- Assistant
Sorting conflict names alone does not preserve the validator’s dictionary insertion order because cell IDs come from sets, and the downstream lint output follows first-seen cell order. Rather than alter longstanding global diagnostics for this fix, I’ll preserve the validator’s original deterministic traversal and use a lookup of conflict-aware cell sets. This retains exact old ordering while filtering out non-conflicting qualified identities. I’ll again restore the snapshot afterward.
- Assistant
Diagnostic ordering is now preserved and the snapshot suite passes unchanged. I’ll perform final verification: targeted lint/dataflow suites, a deletion-and-re-registration scenario at graph/validator level, formatting/diff checks, and confirm only source files changed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.