Unexpected behaviour with on_delete handlers and proxy models (IntegrityError)
|Reported by:||jaap3||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.3|
|Severity:||Normal||Keywords:||ForeignKey on_delete proxy model IntegrityError CASCADE SET_NULL|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Let's say I have a File model and an Image model. The second one being a proxy to the File model, with some additional methods and a manager that only return image-like files.
Another model has a ForeignKey to the Image model. Deleting an Image will trigger the on_delete handlers of it's foreign keys, cascades happen and everything is fine.
Deleting the same thing as an instance of File however will not clean up every objects linking to it. Instead an IntegrityError is raised. It's obvious that the File doesn't know it's also an Image and therefore doesn't trigger the on_delete handler of foreign keys referring to it by a different name.
I don't really see a nice way to work around or fix this problem.
Change History (5)
comment:1 Changed 5 years ago by jaap3
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
Changed 5 years ago by jaap3
comment:3 Changed 5 years ago by carljm
- Resolution set to duplicate
- Status changed from new to closed