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
Let me start by exploring the relevant files mentioned in the issue.
Assistant
Let me look at the
VariableDataclass to understand thequalified_namefield.Assistant
Let me look at the callers of
get_multiply_definedto understand the impact of changing the return type.Assistant
The callers use
get_multiply_defined()returning a list of names. The contract says the new return type islist[tuple[Name, set[CellId_t]]]. Let me look more carefully at all callers to understand what changes are needed.Let me look at the ipynb converter too.
Assistant
Let me look at the SQL visitor to understand how
nameandqualified_nameare set.Assistant
Let me look at
_defineto understand hownameis used and how it's stored.Assistant
Now let me understand how
register_definitionis called fromgraph.pyto see thenamevalue passed.Assistant
Let me look at the existing tests for this functionality.
Assistant
No tests directly. Let me find related test files for the dataflow/sql definitions.
Assistant
Let me look for the actual test directories and search broadly.
Assistant
Let me look at how
qualified_nameandtableare constructed infind_sql_defs.Assistant
Let me examine each caller in detail.
Assistant
Let me look at the broader test context to understand all the multiply_defined tests.
Assistant
Now let me reproduce the issue with a temporary script.
Assistant
DuckDB isn't installed, so SQL defs aren't being parsed. Let me install duckdb.
Assistant
Let me look at how edges use the definition registry.
Assistant
Let me check how
get_defining_cellsand ownership are used across the codebase.Assistant
Let me check what the
register_definitionreturn value (siblings) is used for.Assistant
Let me look at how
definitionsmembership is used in exceptions and runtime for staleness/pruning.Assistant
Let me search for tests involving schema-qualified SQL and parent/child assertions.
Assistant
Let me look at the test around line 620-760 to understand the SQL edge tests that check parents/children.
Assistant
Let me check
get_referring_cellsimplementation.Assistant
Let me find where the "redefines variables" / "was also defined by" error message is generated.
Assistant
Let me find where the messaging
MultipleDefinitionErroris constructed.Assistant
Let me find where the runtime multiple-definition error is generated (the path used when adding cells interactively).
Assistant
Let me check other places that might use
definitionsfor conflict detection.Assistant
Let me search broadly for any other conflict-detection using definitions or get_defining_cells.
Assistant
Let me check
dataflow/__init__.pyaround line 170-180 (pruning logic).Assistant
Let me check tests for validate_graph / check_for_multiple_definitions.
Assistant
Let me check how underscore/private variables are handled in the visitor (to ensure my change doesn't break that test).
Assistant
Let me verify empirically how underscore variables are handled in the registry.
Assistant
Let me check
_is_valid_cell_referenceto see if stale cells are guarded.Assistant
Let me verify the runtime calls
check_for_errorson cell updates.Assistant
Let me check the context around
VariableDeclarationNotification(runtime.py:1260-1275).Assistant
I have a clear understanding now. Let me reproduce the exact user-facing error first to confirm the source.
Assistant
Confirmed the bug.
xxis a false collision (different schemas), whiledfis a genuine collision (both cells assigndf). Now let me implement the fix indefinitions.py.Assistant
Now let me make the edits. First, add the new data structures:
Assistant
The replace command needs the markers without leading whitespace. Let me redo it.
Assistant
I used the wrong marker. It should be
>>> REPLACE, not<<< REPLACE.Assistant
Now let me add the qualified-identity tracking in
register_definition:Assistant
Now let me update
unregister_definitionsto clean up the qualified-identity tracking:Assistant
Now let me rewrite
get_multiply_definedto use conflict-aware grouping:Assistant
Now let me update
graph.py'sget_multiply_definedto extract names (preserving itslist[Name]contract):Assistant
Now let me update
check_for_multiple_definitionsinvalidate_graph.pyto use the conflict-aware registry method:Assistant
I need to open
validate_graph.pyfirst since the editor is ongraph.py.Assistant
Now let me run the reproduce script to confirm the fix:
Assistant
The fix works.
xxis no longer a false collision. Let me run a comprehensive test covering all the edge cases:Assistant
Case 7 returns two collision groups (both leaf "xx") — that's correct behavior. My test assertion was wrong. Let me fix the test:
Assistant
All edge cases pass. Now let me run the existing relevant tests to make sure nothing breaks.
Assistant
Let me check whether these failures are pre-existing (unrelated to my change) by stashing my changes.
Assistant
These failures are pre-existing (they fail without my changes). They're likely due to a missing
sqlglotdependency. Let me check:Assistant
sqlglotis missing, causing the pre-existing SQL ref-parsing failures. Let me install it and re-run:Assistant
All 66 tests pass now (the failures were due to the missing
sqlglotdependency). Let me run the broader test suites that might be affected by my changes:Assistant
Let me install
nbformatto run theto_ir.pyconversion tests (a caller ofget_multiply_defined):Assistant
Let me run the runtime, app, and AI tool tests that touch these code paths:
Assistant
Let me check whether these
test_app.pyfailures are pre-existing by stashing my changes:Assistant
The same 16
test_app.pyfailures are pre-existing (kernel/embed-related). Let me installipykernelto confirm my change doesn't break them:Assistant
Let me look at one failing test to confirm it's unrelated to my change:
Assistant
The failures are due to missing
pytest-asyncio(async tests). Let me install it and re-run:Assistant
All
test_app.pytests pass now (failures were environmental). Let me run the AI dependency-graph tool tests and_code_modetests:Assistant
Let me verify the
TestPackagesfailures are pre-existing and unrelated to my change:Assistant
The
TestPackagesfailures are pre-existing (unrelated). Now let me run the runtime tests that exercisecheck_for_errorsat runtime:Assistant
Let me check what "SQL deps not available" means for those skipped runtime tests:
Assistant
HAS_SQLrequirespolars. Let me install it and run the full runtime SQL test class:Assistant
Let me check if
test_sql_query_as_local_dfis pre-existing by stashing:Assistant
test_sql_query_as_local_dfis pre-existing (fails without my changes too). Let me run the runner and strict lifecycle tests that useget_defining_cells:Assistant
Let me verify the exact issue scenario (bare
mo.sqlcells, nodf =assignment):Assistant
The exact issue scenario is fixed. Let me also verify genuine collisions still raise errors:
Assistant
Let me verify the frontend determines conflicts from
MultipleDefinitionError(not fromdeclared_bylength), to ensure the fix fully resolves the UI error:Assistant
Confirmed end-to-end: the frontend's "redefines variables" message is driven entirely by
multiple-defserrors fromcheck_for_multiple_definitions, which I fixed. Let me clean up temp files and review the final diff:Assistant
Let me deduplicate names in
graph.get_multiply_defined()to preserve the original uniqueness semantics (the original returned unique dict keys; with per-identity grouping, the same leaf can appear twice for separate collision groups):Assistant
I need to open graph.py first:
Assistant
Now let me re-run the key test suites to confirm everything still passes after the dedup change:
Assistant
Let me do a final verification of the dedup behavior and the issue case:
Assistant
Let me double-check no tests directly assert the registry's
get_multiply_definedreturn type (which I changed):Assistant
Only
graph.get_multiply_defined()(thelist[Name]wrapper) is tested — my registry change is safe. Let me run the full lint test suite and a broader sweep:Assistant
Let me run the CLI export and script-run tests that catch
MultipleDefinitionError:Assistant
These are pre-existing environment-related failures (watch/playwright/matplotlib). Let me verify
Nameis imported in graph.py for my type annotation:Assistant
Nameis available (via TYPE_CHECKING +from __future__ import annotations). Let me do a final review of the completedefinitions.py:Assistant
Let me test a delete + re-register cycle to ensure qualified tracking stays consistent:
Assistant
Excellent! The delete/re-register cycle works correctly. Let me run the complete set of directly-affected tests one final time:
Assistant
All 370 tests pass. Let me view the final complete diff one more time to confirm everything is clean:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.