#28332 closed Bug (fixed)
Diamond multiple inheritance example in docs gives a clashing field check error
Reported by: | Luc Saffre | Owned by: | Jeremy Satterfield |
---|---|---|---|
Component: | Documentation | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I need help with getting to test some code which is AFAICS equivalent to the second example (Piece, Book, Article, BookReview) of the Multiple inheritance section of the Models topic guide.
To reproduce my problem, please download the following files from this directory of my repository:
- main/models.py
main/__init__.py
manage.py
settings.py
and then run:
$ python manage.py check
The output is:
SystemCheckError: System check identified some issues: ERRORS: main.PizzeriaBar: (models.E005) The field 'restaurant_ptr' from parent model 'main.bar' clashes with the field 'restaurant_ptr' from parent model 'main.pizzeria'.
The failure works in Django versions 1.11.2, 1.10.7, 1.9.13 (and maybe earlier as well).
I could not find any relevant difference between my code and the example in the documentation.
Any hints?
Change History (5)
comment:1 by , 7 years ago
Component: | Uncategorized → Documentation |
---|---|
Summary: | Cannot get diamond multiple inheritance example to work → Diamond multiple inheritance example in docs gives a clashing field check error |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 7 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
The PizzeriaBar
model is inheriting the restaurant_ptr
field from both Pizzeria
and Bar
, so you need to specify the parent link field on at least one of them, per https://docs.djangoproject.com/en/dev/topics/db/models/#specifying-the-parent-link-field. This gets a little complicated if you are creating this child model and overriding these field names at a later date than the parent since you are changing the field name, it is going to require using the db_column
arg on the field or more complex migrations.
This seems to me to have a lot of caveats to be provided as an example in the docs; however, here is a PR that updates the existing example to be working.
comment:3 by , 7 years ago
I confirm that this fixes the problem. Yes, diamond inheritance has more problems than this (see my blog for an example) and I currently avoid it in my projects. But still it is a feature for Django and I recommend to not remove if from the docs (but to rather write more about it).
It looks like the example in the documentation (added in #22442) never worked. I tested back to Django 1.7 and the check error is the same. If it cannot be fixed, perhaps it should be removed.