🐛 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
-- 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.
- Assistant
Now let me look at edges.py to understand how definitions are consumed for edge computation:
- Assistant
Now the conflict-aware
get_multiply_defined: - Assistant
Now update
graph.py's delegation signature: - Assistant
Now the other callers.
app.py: - Assistant
to_ir.py: - Assistant
_code_mode/_context.py: - Assistant
dependency_graph.pytool: - Assistant
Now update the tests. First check how SQL tests are gated in
test_dataflow.py: - Assistant
Now update the existing test expectations and add regression tests for the repro:
- Assistant
Now run the relevant tests:
- Assistant
Now verify the actual user-facing path (
check_for_errors, which produces the notebook error) with the exact repro: - Assistant
All behaviors check out. Now run the broader affected test suites and the type/lint check:
- Assistant
Pre-existing. Run the format check that got short-circuited:
- Assistant
That failure is pre-existing (fails on clean tree too). Continue the suite past it:
- Assistant
The fix is complete. Here's a summary of what was done:
Root cause
In
DefinitionRegistry.register_definition(marimo/_runtime/dataflow/definitions.py), two SQL cells creating tables with the same leaf name (xx) in different schemas both shared the typed definition("xx", "table"), so the qualified-name dedupe branch was skipped and both cells landed indefinitions["xx"]— whichcheck_for_multiple_definitionsthen reported as a redefinition error.Changes
marimo/_runtime/dataflow/definitions.py— restructured the registry around qualified identity:- New
qualified_definitions: dict[Name, dict[CellId_t, Name]]field tracks each definition's identity per cell: the fully qualified SQL name (finance.datalake.xx) for qualified SQL defs, the name itself otherwise. register_definitionalways records defining-cell ownership indefinitions[name](preserving the user-facing table variable), and returns siblings based on identity conflicts.get_multiply_definednow returnslist[tuple[Name, set[CellId_t]]], grouping definitions by qualified identity — same fully qualified name or same unqualified name in multiple cells still conflicts; same leaf name in different schemas/catalogs does not.unregister_definitionsnow cleans uptyped_definitionsper cell instead of only when the name fully disappears — the old code both leaked entries for deleted cells and clobbered a surviving sibling's typed defs when the lastdefinitions[name]entry was removed.
marimo/_lint/validate_graph.py—check_for_multiple_definitions(the source of the user-facing notebook error) now builds errors from the conflict-awareget_multiply_defined()groups instead of rawdefinitions[name]cardinality.Callers adapted to the new return type:
graph.py(delegation + docstrings),app.py([0][0]in the error message),to_ir.py,_code_mode/_context.py,_ai/_tools/tools/dependency_graph.py.Tests — updated existing expectations in
tests/_runtime/test_dataflow.pyand added three regression tests: the discussion's exact repro (different schemas → no conflict, ownership and deletion verified), same fully qualified name in two cells → conflict, and same unqualified name → conflict.Verification
- End-to-end: the repro now produces no errors through
check_for_errors; genuine Python and SQL collisions still reportMultipleDefinitionErroridentically. - Edges still resolve to the correct schema's cell (
SELECT * FROM finance.datalake.xxdepends only on thefinance.datalake.xxcell), and deleting one cell leaves the sibling's definitions intact. - ~2,700 tests pass across
tests/_runtime,tests/_ast,tests/_lint,tests/_convert,tests/_code_mode,tests/_save,tests/_ai; the one failure (test_duckdb_wasm.py) and all mypy/ruff findings were confirmed pre-existing on the clean tree.
- New
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →