Skip to content

delete(): report the rows deleted from each table, and allow a per-table check inside its transaction #1761

Backlog

Description

@dimitri-yatsenko

Problem

delete() returns only the number of rows deleted from the table it was called on. The other tables of the cascade are reported only in log lines.

A caller that needs any of the following has to reimplement delete()'s loop around Diagram.cascade() and delete_quick(get_count=True):

  • the number of rows deleted from each table;
  • progress while a long delete runs;
  • a check between tables, such as stopping when a table holds more rows than a preview counted.

A reimplemented loop drifts from the library's. In 2.4, delete() moves onto the traversal planner (#1637), and a delete has to read some restrictions before it deletes anything: lifts from a part to its master, and seeds that read their own descendants (#1496). A copied reversed(diagram) loop would skip that step and delete too little, without an error.

Proposal (to be designed)

  1. delete() reports the rows deleted from each table: for example a result whose rows maps full table names to counts, with the root's count still available as today.
  2. An optional per-table hook: a callable that delete() calls inside its transaction after each table, with the table's name and count. If the hook raises, the delete rolls back. Callers can then show progress, or compare each count with a preview, without owning the loop.
  3. Possibly, as a shortcut for the common check: delete(expected=...), taking the per-table counts of a preview (Diagram.cascade(...).counts()) and rolling back if any table would lose more rows than expected.

Questions

Activity

  1. added this to the v2.4 milestone on Nov 25, 2026
  2. added
    feature
    on Nov 25, 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

    feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions