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
Good, return value is discarded. Now let's check the tests file for dataflow to understand expected behavior/tests around get_multiply_defined and SQL definitions.
Assistant
Now let's update
graph.py'sget_multiply_definedto keep list[Name] output for backward compatibility with existing callers/tests.Assistant
Now let's check other usages that call
get_multiply_definedat the graph level (not definitions.py level) to ensure they still work since we preserved list[Name] there. Let's also double check_code_mode/_context.pyusage which needs cell_ids for detail messages - let's view more context.Assistant
This uses
graph.get_multiply_defined()(list[Name]) unaffected by our change since we kept graph-level API stable. Good. Now let's run the existing test suite for dataflow.Assistant
There's a proper venv. Let's run tests using it.
Assistant
All pass. Now let's write a reproduce script for the issue scenario, and run broader test suites related to dataflow/graph.
Assistant
All scenarios behave as expected. Now let's run the broader test suite touching dataflow, definitions, graph, code_mode, and ai tools.
Assistant
Confirmed pre-existing failure unrelated to our change (environment permission issue with
os.setsid()). Now let's run other relevant tests:_ast,_code_mode,_ai/_tools,_convert.Assistant
Confirmed pre-existing failures unrelated to our change (package manager environment issue). Now let's double check
_ai/_toolstest for dependency_graph that mocksget_multiply_defined.Assistant
Now let's inspect the diff overview and finalize.
Assistant
Now let's clean up the reproduce script.
Assistant
Now let's run tests again for validate_graph, runtime, dataflow.
Assistant
Only pre-existing unrelated failure. Now let's write an end-to-end kernel reproduction test to fully verify the issue is fixed at the runtime level.
Assistant
The real-time error path is fixed too. Let's clean up and run the full test suite for good measure (dataflow, runtime, lint, ast, ai, code_mode, convert).
Assistant
Same 11 pre-existing unrelated failures as before (confirmed earlier as pre-existing). All other tests pass. Let's view the final diff.
Assistant
Looks correct. Now let's run ruff to check formatting/lint compliance.
Assistant
Good, formatted correctly. Let's confirm the pre-existing lint errors in graph.py are unrelated (pre-existing) by checking on clean checkout.
Assistant
Confirmed pre-existing lint issues unrelated to our change. Now let's run tests once more after formatting fix, and check ruff on definitions.py again (already passed).
Assistant
Only the known unrelated failure remains. Let's finalize by reviewing full diff once more.
Assistant
This all looks good. Let's re-run the full previously-failing area one more time plus a broader sanity sweep including
_servertests that might use these paths (export etc.), and_convert.Assistant
All relevant tests pass. Let's also test a scenario with three schemas and mixed conflicts to ensure robustness, plus verify
_conflict_keysinternal name mangling doesn't break dataclass field defaults (leading underscore is fine for dataclasses).Assistant
Deletion behavior and multi-cell conflict grouping work correctly. Now let's do a final full test run to make sure nothing else broke.
Assistant
Confirmed this failure is pre-existing and unrelated to our changes (happens identically without our diff, likely test-order/environment pollution issue with
anywidget). Let's continue running the rest of the suite without-xto get overall summary excluding known unrelated failures.Assistant
No lingering processes. Let's do a final review of the diff and confirm nothing stray was left (like temp files).
Assistant
Clean. Now let's go through the checklist explicitly.
Checklist Review
-
Reproduced the reported error: Yes. I wrote a reproduce script that registered two SQL cells creating tables with the same leaf name (
xx) in different schemas (finance.datalake.xxandfinance.information_layer.xx), and confirmed viacheck_for_multiple_definitions(the actual runtime code path that produces the "This cell wasn't run because it has errors... was also defined by" message) that it originally flagged this as a conflict — matching the bug report. -
Confirmed the fix resolves the error: Yes. After the fix, the same reproduction script shows
check_for_multiple_definitionsreturns no errors for the two different-schema tables, while it still correctly reports a conflict when both cells define the exact same fully-qualified name (e.g., bothfinance.datalake.xx) or the same unqualified name — preserving genuine collision detection.
-
Assistant
- Thought about edge cases: Considered and tested:
- Different schemas with the same leaf name → no conflict (the core issue).
- Same fully-qualified name defined by two cells → genuine conflict still detected.
- Same unqualified name defined by two cells → genuine conflict still detected.
- Mixed Python variable vs. unqualified SQL table name collision (existing tests
test_sql_table_schema_to_python_ref/_rev) → still detected as conflict, unaffected. - Python variable vs. SQL qualified table sharing leaf name in different schema (
test_redefine_sql_table_diff_schema) → still not a conflict. - Cell deletion properly cleans up the new internal
_conflict_keystracking structure so it doesn't leak stale state (verified with a deletion test where removing a conflicting cell resolves the conflict). - Multiple simultaneous conflicting name groups per cell (, ) — verified ordering/behavior still matches existing kernel tests ().
- Thought about edge cases: Considered and tested:
Assistant
- Ran existing tests affected by the change: Ran
tests/_runtime/test_dataflow.py,tests/_runtime/test_runtime.py,tests/_lint(includingtest_validate_graph.py),tests/_ai/tools/tools/test_dependency_graph.py,tests/_code_mode,tests/_convert, andtests/_ast. All pass except pre-existing, environment-related failures (os.setsid()permission error in sandboxed environment,anywidgetAPI mismatch causing test-order pollution, and package-managerpixiabsence) that I verified also fail identically on the unmodified codebase (viagit stash), confirming they are unrelated to this change.
All checklist items are satisfied. The fix is complete and correctly scoped:
DefinitionRegistry() now tracks a "conflict key" per cell/name (the fully qualified SQL name when available, otherwise the plain name), and groups cells by this conflict key to detect genuine redefinitions while ignoring same-leaf-name-different-qualification cases, per the interface contract.
- Ran existing tests affected by the change: Ran
Assistant
The changes are complete, tested, and ready for submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.