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
Now let's implement changes. First update
definitions.py.Assistant
Now let's update the graph.py wrapper's type signature and the callers.
Assistant
Now update callers. First
to_ir.py:Assistant
Now update
app.py:Assistant
Now update
_code_mode/_context.py:Assistant
Now update
dependency_graph.py:Assistant
Now let's search for any other references to
get_multiply_definedwe might have missed, including tests.Assistant
Need duckdb installed to run these SQL-related tests.
Assistant
Let's look at edges.compute_edges_for_cell to see how it uses find_sql_hierarchical_matches etc.
Assistant
Now let's write a reproduction script matching the exact issue scenario (two different schemas, same catalog) to confirm the fix resolves it.
Assistant
The fix works as intended. Now let's run broader test suites to check nothing else broke.
Assistant
Missing pytest-asyncio plugin. Let's install it.
Assistant
Good, all pass now. Let's run the full test_app.py and to_ir tests, plus code_mode context tests.
Assistant
Let's run the full suite for those two files, and check to_ir tests too.
Assistant
Confirmed pre-existing, unrelated to our changes. Now let's check to_ir tests.
Assistant
All pass. Now let's run the whole dataflow-related test suite and the runtime test suite to be thorough.
Assistant
All these are pre-existing failures unrelated to my change (identical failure set with/without my changes — 28 failed both before and after). Let's confirm test_package_utils and test_runtime.py failures are also pre-existing.
Assistant
Confirmed all pre-existing, environment related. Only new failures introduced are the 2 format-change tests in test_dataflow.py, which are expected given the interface change. Let's also check
marimo/_types/ids.pyimport in graph.py works fine (CellId_t import already present).Assistant
Good,
from __future__ import annotationsmakes type hints lazy, soCellId_tused in the annotation doesn't need to be imported at runtime. Let's double check mypy/type checking passes too.Assistant
Let's view the final diff for review.
Assistant
Now let's re-run tests to confirm nothing broke with this update.
Assistant
Good, consistent with expectations (only the format-change failures remain, which are expected). Now let's test with schemas/catalogs collision case (same schema name defined by two cells) to be thorough.
Assistant
All edge cases behave as expected. Let's cleanup temp scripts and do a final full diff review.
Assistant
Let's run the full targeted test suites once more to be safe, plus check ruff lint passes.
Assistant
Pre-existing lint issues unrelated to our changes. Let's format with ruff format to keep style consistent.
Assistant
All formatted correctly. Now let's run the full relevant test set once more for a final sanity check.
Assistant
Let's explicitly verify the pre-fix code exhibits the bug (to satisfy the checklist requirement of confirming reproduction before fix).
Assistant
Confirmed bug on pre-fix code. Now verify fix resolves it with current code.
Assistant
The fix is confirmed working. Let's do a final review of the diff.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.