🐛 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 the remaining consumers of
get_multiply_defined: - Assistant
I have the full picture. Now let me implement the fix, starting with
DefinitionRegistry: - Assistant
Now update the
DirectedGraphwrapper: - Assistant
Now update
check_for_multiple_definitionsin the lint validator: - Assistant
Now the other consumers. First
to_ir.py: - Assistant
Now
app.py: - Assistant
Now
dependency_graph.py: - Assistant
Now add new tests covering the bug. Insert after
test_redefine_sql_table_diff_schema: - Assistant
Now update the mock in
test_dependency_graph.pyto match the new return format: - Assistant
Now run the relevant tests:
- Assistant
Confirmed pre-existing. Now let me run an end-to-end check reproducing the exact bug scenario from the issue:
- Assistant
The bug scenario now passes and genuine collisions still error. Run the broader test suites:
- Assistant
All passing. Now run the typecheck and lint:
- Assistant
Those 5 ruff findings are pre-existing docstrings in
graph.pyI didn't touch — confirm against the clean tree: - Assistant
Let me verify the
Appinitialization path end-to-end too: - Assistant
The f-string in my test gets normalized to a placeholder schema, so that wasn't a genuine collision. Let me fix the test script:
- Assistant
One docstring is now stale —
get_defining_cellsclaims well-formed graphs have singleton definers, but distinct-schema tables now legitimately share a leaf name. Update both: - Assistant
Final sweep to confirm all call sites are consistent with the new signature:
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.