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
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
- Assistant
I'll start by exploring the repository structure and locating how SQL table definitions and multiply-defined variable checks are handled.
- Assistant
The key file is
definitions.py; I'll read it and search for SQL-related definition handling. - Assistant
Let me read the rest of the definitions.py file and search for related code.
- Assistant
The contract says
get_multiply_definedshould return(name, cell_ids)with conflict-aware grouping for SQL. I'll inspect the related registration and test code next. - Assistant
I'll inspect how definitions get registered and how existing multi-schema SQL tests behave.
- Assistant
Let me look at how register_cell works and how visitor defines SQL tables - specifically at the name used as the key vs qualified_name.
- Assistant
I'll check how callers use
get_multiply_definedand whether anything already tracks qualified SQL identity. - Assistant
I'll inspect the multiple-definition check and any recent related git history.
- Assistant
Interesting -
check_for_multiple_definitionsusesgraph.definitions[name]directly, notget_multiply_defined. So the fix needs to be in how definitions are registered/tracked, not just in `get_m... - Assistant
I need to understand all the places that consume definition tracking so the fix won't break callers.
- Assistant
There's a test for different schemas already; I'll reproduce the bug and inspect how sibling registration interacts with it.
- Assistant
I'll check how siblings and signature usage fit into edge computation together.
- Assistant
I'll check the graph definitions property and a few more callers before implementing.
- Assistant
I have a clear plan: track SQL qualified identities, make
get_multiply_definedconflict-aware by identity, and update the callers that depend on it. - Assistant
I'll implement identity tracking and conflict-aware
get_multiply_definedindefinitions.py. - Assistant
_definition_identityneedsVariableDataat runtime; I'll fix the import and then update the callers. - Assistant
Next I'll update the graph wrapper and all callers of
get_multiply_defined. - Assistant
Need to open the file first or use edit with line numbers.
- Assistant
Now I can replace.
- Assistant
I'll update
validate_graph.pyand the other callers next. - Assistant
I'll update the remaining callers to handle the new return type.
- Assistant
Continue with Other callers.
- Assistant
Continue with code_mode and dependency_graph.
- Assistant
I need to also fix the new_multiply_defined line.
- Assistant
Now dependency_graph.py
- Assistant
I'll check for circular imports, then reproduce the bug and run the related tests.
- Assistant
The repro cases look correct. Next I'll run the related unit tests.
- Assistant
I'll restore the lint snapshot and make multiply-defined reporting order deterministic again.
- Assistant
I'll sort the results by name for deterministic order.
- Assistant
I'll inspect how the lint snapshot orders multiple-definition errors.
- Assistant
Snapshot order is fixed. I'll rerun the related tests and a few more caller suites.
- Assistant
Package test failures look unrelated. I'll focus on the multiply-defined cases next.
- Assistant
I'll double-check the dataflow cases and review the final diff.
- Assistant
I'll run the full dataflow cases suite to confirm nothing regressed.
- Assistant
I'll do a final review of the core definitions file.
- Assistant
I'll quickly confirm the import chain doesn't create a cycle.
- Assistant
Syntax error from my bad one-liner.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.