Models with multiple inlines inheriting from the same parent class do not save properly in admin
|Reported by:||idangazit||Owned by:||Alex|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I've attached a model graph and screenshots which illustrate the problem a lot more clearly than my words, but bear with me. I've tried my best to make it unconfusing. :)
Basically, I can reproducibly make the admin issue incorrect INSERT statements when saving a model with inlines.
I have a model with inlines of multiple classes (all of which inherit from a common parent). When I create a new instance of the model, it will use only the data from the LAST inline to create all of the model instances for ALL the inlines.
For example: I have two models, TwitterAccount and DeliciousAccount, both of which inherit from Account. Both are displayed inline in the model admin for the Persona model. When creating a new persona, I enter data for a new TwitterAccount and a new DeliciousAccount on the add page for Persona. When I click save, I find that there are (correctly) one new TwitterAccount and one new DeliciousAccount, but (incorrectly) both new accounts are populated with the data I entered for the DeliciousAccount.
I've verified that this behavior only occurs for the pages with the inlines:
- Model instance creation works as expected from ./manage.py shell
- Model instance creation works as expected if I create the instances one-by-one from a model-specific admin page and not via inlines
Attached you'll find three PNGs:
- 1_admin.png: shows the admin add page for the model with the inlines. Note that the data entered for each inline is different.
- 2_sql.png: using the django-debug-toolbar, shows the SQL statements executed after clicking Save. Note that delicious999 is the only data used when creating the inlined model instances. The twitter account is still created — but using the delicious account's data.
- model_graph.png: shows the models in the application. The various accounts all inherit from Account, the various activities inherit from Activity.
I'd love to help in fixing this bug but I could use some guidance on what to do next. Thank you!
Change History (13)
Changed 5 years ago by Alex
comment:1 Changed 5 years ago by Alex
- Has patch set
- Needs documentation unset
- Needs tests set
- Patch needs improvement unset