You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
delete(): report the rows deleted from each table, and allow a per-table check inside its transaction #1761
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)
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.
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.
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
What the hook may do inside the transaction: read only, or also query the database?
Activity