Skip to content
TheChatArchiveThe Chat Archive
fable-5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

🐛 Bug ❓: Variable name collision for SQL cells using same table name in different…

  1. User

    🐛 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.

  2. Assistant

    Now let me look at edges.py to understand how definitions are consumed for edge computation:

  3. Assistant

    Now the conflict-aware get_multiply_defined:

  4. Assistant

    Now update graph.py's delegation signature:

  5. Assistant

    Now the other callers. app.py:

  6. Assistant

    to_ir.py:

  7. Assistant

    _code_mode/_context.py:

  8. Assistant

    dependency_graph.py tool:

  9. Assistant

    Now update the tests. First check how SQL tests are gated in test_dataflow.py:

  10. Assistant

    Now update the existing test expectations and add regression tests for the repro:

  11. Assistant

    Now run the relevant tests:

  12. Assistant

    Now verify the actual user-facing path (check_for_errors, which produces the notebook error) with the exact repro:

  13. Assistant

    All behaviors check out. Now run the broader affected test suites and the type/lint check:

  14. Assistant

    Pre-existing. Run the format check that got short-circuited:

  15. Assistant

    That failure is pre-existing (fails on clean tree too). Continue the suite past it:

  16. Assistant

    The fix is complete. Here's a summary of what was done:

    Root cause

    In DefinitionRegistry.register_definition (marimo/_runtime/dataflow/definitions.py), two SQL cells creating tables with the same leaf name (xx) in different schemas both shared the typed definition ("xx", "table"), so the qualified-name dedupe branch was skipped and both cells landed in definitions["xx"] — which check_for_multiple_definitions then reported as a redefinition error.

    Changes

    marimo/_runtime/dataflow/definitions.py — restructured the registry around qualified identity:

    • New qualified_definitions: dict[Name, dict[CellId_t, Name]] field tracks each definition's identity per cell: the fully qualified SQL name (finance.datalake.xx) for qualified SQL defs, the name itself otherwise.
    • register_definition always records defining-cell ownership in definitions[name] (preserving the user-facing table variable), and returns siblings based on identity conflicts.
    • get_multiply_defined now returns list[tuple[Name, set[CellId_t]]], grouping definitions by qualified identity — same fully qualified name or same unqualified name in multiple cells still conflicts; same leaf name in different schemas/catalogs does not.
    • unregister_definitions now cleans up typed_definitions per cell instead of only when the name fully disappears — the old code both leaked entries for deleted cells and clobbered a surviving sibling's typed defs when the last definitions[name] entry was removed.

    marimo/_lint/validate_graph.py — check_for_multiple_definitions (the source of the user-facing notebook error) now builds errors from the conflict-aware get_multiply_defined() groups instead of raw definitions[name] cardinality.

    Callers adapted to the new return type: graph.py (delegation + docstrings), app.py ([0][0] in the error message), to_ir.py, _code_mode/_context.py, _ai/_tools/tools/dependency_graph.py.

    Tests — updated existing expectations in tests/_runtime/test_dataflow.py and added three regression tests: the discussion's exact repro (different schemas → no conflict, ownership and deletion verified), same fully qualified name in two cells → conflict, and same unqualified name → conflict.

    Verification

    • End-to-end: the repro now produces no errors through check_for_errors; genuine Python and SQL collisions still report MultipleDefinitionError identically.
    • Edges still resolve to the correct schema's cell (SELECT * FROM finance.datalake.xx depends only on the finance.datalake.xx cell), and deleting one cell leaves the sibling's definitions intact.
    • ~2,700 tests pass across tests/_runtime, tests/_ast, tests/_lint, tests/_convert, tests/_code_mode, tests/_save, tests/_ai; the one failure (test_duckdb_wasm.py) and all mypy/ruff findings were confirmed pre-existing on the clean tree.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.