Skip to content

part_integrity="cascade" deletes masters that have no matching part rows #1591

Closed

Description

@dimitri-yatsenko

With part_integrity="cascade", deleting part rows can delete masters that have no matching part rows, together with everything downstream of those masters.

@schema
class Master(dj.Manual):
    definition = """
    master_id : int32
    """

    class P(dj.Part):
        definition = """
        -> master
        p_id : int32
        """

Master.insert([(1,), (2,)])
Master.P.insert([(1, 1)])          # master 2 has no parts
(Master.P & [{"master_id": 1}, {"master_id": 2}]).delete(prompt=False, part_integrity="cascade")
len(Master())   # 0 — expected 1: master 2 had no matching part row

Cause. The part-to-master lift copies the part's condition to the master whenever the restricted attributes are in the master's primary key (Diagram._apply_propagation_rule_upward, Rule 1). That selects every master satisfying the condition, not the masters of the part rows that matched.

Workaround until the fix ships: restrict the parts by keys that exist, e.g. Master.P & (Master.P & cond).keys(), or use the default part_integrity="enforce".

Fix: the lift restricts the master by the restricted part, master & part_restricted.proj(...), so a master joins the cascade only if one of its part rows did.

Activity

  1. added this to the v2.3.5 milestone on Oct 17, 2026
  2. added
    bugIndicates an unexpected problem or unintended behavior
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions