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 start by exploring the repository structure and locating how SQL definitions and multiply-defined variable checks work.
- Assistant
I'll inspect the definitions module and search for how SQL table names are tracked.
- Assistant
Let me continue reading the file and search with grep instead of rg.
- Assistant
Looking at visitors, graph usage of multiply-defined names, and related tests next.
- Assistant
I'll inspect the multiply-defined tests and how SQL definitions become cell variables.
- Assistant
Checking VariableData and how definitions are consumed for collisions.
- Assistant
Let me look at how MultipleDefinitionError is raised and validate_graph uses get_defining_cells. Also let me check git log for recent related work.
- Assistant
I'll inspect the PR that introduced qualified-name shadowing and related edge/definition tests.
- Assistant
Next I'll inspect edges/siblings and all DefinitionRegistry consumers so the fix stays consistent.
- Assistant
I'll read the remainder of edges and how definitions are looked up for SQL refs.
- Assistant
Reproducing the reported bug and checking how definitions currently collide.
- Assistant
Checking how missing
definitionsentries affect graph operations and related utilities. - Assistant
Checking how definitions and multiply-defined flags are published to the frontend.
- Assistant
Interesting - when deleting SQL tables:
- Assistant
I'll verify collision rules for schemas, catalogs, and mixed Python/SQL cases.
- Assistant
Checking asymmetry cases between reverse and matching SQL qualifications.
- Assistant
Searching for other multiplicity checks tied to
definitions. - Assistant
Confirming whether
register_definition's return value is used, then implementing the fix. - Assistant
Implementing conflict-aware identity tracking and updating all call sites.
- Assistant
The edit landed in the wrong file; I'll restore
edges.pyand apply the change todefinitions.py. - Assistant
I'll rewrite
definitions.pywith the full fix. - Assistant
Updating graph return type and callers next.
- Assistant
I need to update the get_multiply_defined signature to use CellId_t.
- Assistant
Now update validate_graph.py
- Assistant
Updating the remaining production callers of
get_multiply_defined. - Assistant
sed failed due to syntax. Let me edit the files properly.
- Assistant
I introduced a syntax error in app.py with an extra
). Let me fix that and update code_mode. - Assistant
Updating code_mode to handle unhashable cell_id sets in multiply-defined results.
- Assistant
There's an extra
)on line 1632. Need to fix that. - Assistant
Update dependency_graph and to_ir.
- Assistant
Verifying the fix against the original reproduction and related edge cases.
- Assistant
Syntax error from typos. Let me rewrite the script cleanly.
- Assistant
Main cases pass. I'll recheck catalog qualifications and a three-way collision.
- Assistant
I keep making typos. Let me be more careful.
- Assistant
I'll write a temporary test script file to avoid more heredoc typos.
- Assistant
Running the dataflow and lint tests to verify nothing important regressed.
- Assistant
Confirming intended dataflow assertion updates and that multiply-defined validation still works.
- Assistant
Re-running the dataflow multiply-defined tests without the name filter.
- Assistant
Failure is only the old list-of-names assertion. Next I'll run dataflow cases and check file syntax.
- Assistant
Dataflow cases all passed. Verifying syntax of the modified modules next.
- Assistant
Restoring the accidentally modified snapshot file from the lint tests.
- Assistant
Final review of the core definitions module, then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.