Skip to content

Cube create/deploy raises pk_cube UniqueViolation when a dimension column is used under multiple roles #2294

Description

@shangyian

Version: 0.0.192

NodeRevision.cube_elements is a list-backed many-to-many over the cube table, whose PK is (cube_id, cube_element_id). When a cube references the same dimension column under more than one role, both roles resolve to the same Column, so the element list gets a duplicate and flush fails:

(psycopg.errors.UniqueViolation) duplicate key value violates unique constraint "pk_cube"
DETAIL: Key (cube_id, cube_element_id)=(...) already exists.

Repro: create/deploy a cube whose dimensions include store.day[open_day] and store.day[close_day] — the same physical store.day column under two roles. The create (or the whole deployment transaction) rolls back.

Cause: datajunction_server/internal/deployment/orchestrator.py:2677 (and datajunction_server/internal/nodes.py:679) set cube_elements=metric_columns + dimension_columns with no dedup; the role is stripped when resolving the physical column at orchestrator.py:2353-2369, so a repeated-role dimension appends the same Column twice.

Fix: dedup preserving order, e.g. cube_elements=list(dict.fromkeys(metric_columns + dimension_columns)), in both paths; add a regression test for

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions