The only deletions that are missing in session.deleted before the flash are those that will occur, because a particular object is an “orphan” and objects that will be deleted as a result of the cascade of this orphan.
Thus, without orphans, session.deleted tells you everything you need to delete.
In order to take orphans into account, it is necessary to go through all the relationships, as the unit of work does, looking for objects that are currently orphans (there is an API function that tells you this - if an object is considered an “orphan” by any attribute that refers to him with the help of syntactic deletion, he is considered an “orphan”), and then crosses the relations of these orphans, considering them marked as “deleted”, and then again fulfills all the rules for those deleted objects.
The system is now implemented by the orm / dependency.py command. It’s probably not difficult to literally launch a workflow unit in a session, usually, but just not emit SQL, this will give you the final flash plan. But this is an expensive process that I would not want to constantly call.
Adding a function is difficult here because the use case is not clear. Knowing what will be deleted basically requires that half of the flash process actually continues. But you can already implement events within the flush process itself, most immediately before the before_delete () and after_delete () events, which are guaranteed to catch everything. So, the rationale for a new feature that basically works on half a flash before you just make a flash anyway and can just put events inside it is not clear.
I think the big question is, "When do you call it."
An easy system would be to add a new event, “flush_plan_complete”, which puts you in flash () as soon as the complete plan is built, but before any SQL occurs. This may allow you to register more objects for activity, and then re-run the flash plan to consider any new changes (as it works now anyway). How this registration will continue is difficult, since it would be nice to use the session, as a rule, there, but this complicates the implementation. But then it can be called again with the new changes and find all the remaining steps before proceeding normally.