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 explore the repository structure and locate how SQL table definitions and multiply-defined variables are tracked.
- Assistant
I'll inspect
definitions.pyand search for SQL name/qualification handling. - Assistant
Let me read the rest of the definitions.py file and search with grep instead.
- Assistant
Examining how definitions are registered and how callers use
get_multiply_defined. - Assistant
Looking at related graph/edges code and other callers of multiply-defined detection.
- Assistant
Investigating the registration path and existing tests for schema-qualified SQL tables.
- Assistant
Let me look at the original PR that enabled qualified SQL references to shadow regular variables, and reproduce the bug.
- Assistant
Need to activate the venv.
- Assistant
Let me find parse_cell properly.
- Assistant
Let me reproduce with the right imports.
- Assistant
Reviewing how multiply-defined errors and ownership use the definitions registry.
- Assistant
Let me look at validate_graph, lint rules, how MultipleDefinitionError is constructed, and register_definition siblings usage.
- Assistant
Checking for design notes and how definitions / qualified names are stored elsewhere.
- Assistant
Verifying deletion behavior when SQL and Python share a leaf name.
- Assistant
Checking how siblings from register_definition are used.
- Assistant
Let me try with find/grep properly.
- Assistant
Checking sibling handling when variables are shared across cells:
- Assistant
Reviewing callers and any incomplete implementation that points at the intended design.
- Assistant
- Assistant
Inspecting how runtime uses definitions for declared variables:
- Assistant
Checking tests that assert definitions membership for SQL cases:
- Assistant
Inspecting the existing multi-schema test case and how cases are run:
- Assistant
Implementing identity tracking and conflict-aware
get_multiply_defined, then updating callers. - Assistant
Rewriting
definitions.pyto track qualified identities and make multiply-defined detection conflict-aware. - Assistant
Fixing the typo and updating callers next.
- Assistant
Updating the graph wrapper and all callers of
get_multiply_defined. - Assistant
Updating
validate_graph.pyand other callers. - Assistant
Now update app.py, _context.py, dependency_graph.py, to_ir.py
- Assistant
I need to update these callers carefully.
- Assistant
Now update _context.py
- Assistant
Need to also fix the new_multiply_defined computation.
- Assistant
Now update dependency_graph and to_ir
- Assistant
Update to_ir.py
- Assistant
VariableDatais only underTYPE_CHECKING, so I'll fix the runtime import. - Assistant
Checking for circular imports from pulling visitor at runtime:
- Assistant
Reproducing the original bug and running related tests:
- Assistant
Bug is fixed. Running the related dataflow tests:
- Assistant
Those failing asserts are return-type updates; leaving tests alone per instructions. Running more related tests:
- Assistant
There's a test that mocks get_multiply_defined — checking it:
- Assistant
Checking callers that treat get_defining_cells as a singleton:
- Assistant
The
(blamed_cell, *_) = get_defining_cells(ref)works with a set of multiple items - it lands randoon one due toc set py - OK. The issue is that DuckDB allows the same table name in different schemas (e.g.,finance.datalake.xxvsfinance.information_layer.xx), but marimo treats the leaf name"xx"as a collision because it only tracks unqualified names for SQL cells. This triggers the "redefines variables" error even though the fully-qualified names are distinct.The contract requires us to track SQL definitions by their complete qualified identity (schema.table), while still preserving the user-facing table variable (the leaf name) and the defining-cell ownership logic. The old design intentionally kept SQL tables out of the Python-style
definitionsdict when a Python variable already claimed the leaf name (shadowing), but we need to generalize that logic so multiple qualified SQL names with the same leaf are allowed.Here's the fix:
- Always compute and store the full qualified identity for SQL cells.
- Assistant
Those cases are handled correctly — test failures are only return-type shape. Confirming the multi-schema dataflow case:
- Assistant
Confirming whether qualified SQL then Python should conflict:
- Assistant
What was the old behavior?
- Assistant
Snapshot was updated during tests — reverting it. Asymmetric old shadowing behavior noted; new symmetric behavior looks correct.
- Assistant
Polishing a minor docstring and verifying delete(register) with scipy Python+SQL edge cases.
- Assistant
I had typos in the test script. Let me fix the docstring and run a clean test.
- Assistant
Verifying the final state of the core file and a quick lint check:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.