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 variable checks are handled.
- Assistant
I'll inspect
definitions.pyand search for how SQL table names become variables. - Assistant
Let me continue reading the definitions.py file and search for related code.
- Assistant
I'll inspect how SQL definitions are registered and how related tests portray the expected behavior.
- Assistant
I'll inspect existing tests and callers of
get_multiply_defined/register_definitionnext. - Assistant
I'll look for recent commits and other places that track qualified definition identity.
- Assistant
Let me look at validate_graph and MultipleDefinitionsRule more carefully, as well as how MultipleDefinitionError is created.
- Assistant
I'll dig deeper into registration and sibling conflict handling in the related modules.
- Assistant
I'll reproduce the bug and inspect how definition siblings are used.
- Assistant
I'll look for any existing WIP or docs describing the intended fix.
- Assistant
I'll check the original PR that introduced the qualified-name handling to understand the intended design.
- Assistant
Let me get the original register_cell logic around the qualified name handling from git history before the split.
- Assistant
Let me look at the commit that introduced qualified SQL shadowing.
- Assistant
I'll check whether the
siblingsreturn value fromregister_definitionis used. - Assistant
I'll verify hierarchical matching still works when both schemas register the same leaf table name.
- Assistant
I've confirmed edges already handle hierarchy; the multiply-defined check is the bug. I'll implement conflict-aware identity tracking in
DefinitionRegistryand update callers. - Assistant
Implementing identity-based conflict tracking and updating the related call sites.
- Assistant
I'll simplify unregister to match the original structure and only add identity cleanup.
- Assistant
I'll rewrite the full file to straighten out unregister.
- Assistant
I'll check how cell deletion interacts with stale typed_definitions.
- Assistant
Updating the graph wrapper and call sites next.
- Assistant
Need to update CellId_t import in graph if needed for return type.
- Assistant
Update graph.get_multiply_defined return type and docstring.
- Assistant
Now update validate_graph.py - this is the key user-facing path.
- Assistant
Update check_for_multiple_definitions to use get_multiply_defined.
- Assistant
Now update other callers: app.py, to_ir.py, code_mode/_context.py, dependency_graph.py
- Assistant
Update app.py
- Assistant
Now to_ir.py, dependency_graph.py, code_mode
- Assistant
Update the loop.
- Assistant
Now dependency_graph and code_mode
- Assistant
For dependency_graph:
- Assistant
I'll fix runtime imports for
_conflict_identity—NameandVariableDataare currently TYPE_CHECKING-only. - Assistant
Checking for circular import issues, then reproducing the bug and running tests.
- Assistant
The fix works. Next I'll run the related tests.
- Assistant
I'll inspect the dataflow test failures to confirm they're only from the return-type change.
- Assistant
I'll run validate_graph, edges, and dataflow_cases tests plus a few more code_mode checks.
- Assistant
Let me find the right test class names
- Assistant
Let me run the code mode multiply defined tests.
- Assistant
I'll check for circular imports and scan remaining callers that may still expect list[Name].
- Assistant
I'll match the module's TYPE_CHECKING import style since annotations are deferred.
- Assistant
I'll review the full diff and re-run the core scenario once more.
- Assistant
I'll check whether the runtime has any other path that treats multi-cell defs as errors.
- Assistant
I'll glance at the runtime path for multiple-definition handling.
- Assistant
I'll double-check a few more catalog/schema edge cases.
- Assistant
I'll check definition ownership for table vs view edge cases.
- Assistant
I'll do one last review of the definitions module and related tests.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.