Just want to add that's not the only place where this can happen.
If you hook into the post_delete() delete signal of a model with a FK,
your method can't access the FK object if it's a cascaded delete
invoked by the FK object's delete().
I always wondered why children don't get deleted first (which is how
the database _has_ to do it anyway).
My workaround is to delete in the correct order myself but I wish I
didn't have to.
Cheers,
Danny
Good to hear! (and a jquery one-liner can swap the way they are displayed)
And reading this thread gave me an idea of a slightly cleaner workaround:
- either define FK as nullable or provide a "sentinel" FK object for
collecting "deletables"
- set the FK .ondelete to SET_NULL or SET with a callable that assigns
the sentinel
- in the FK object's post_delete() - need to doublecheck if that gets
called last as well -, clean out all the objects referencing
None/sentinel
But it's still just a workaround. It appears to me like deleting
dependent objects first would avoid the problem altogether (can't
think of negative side effects).
Cheers,
Danny