Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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:

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 Tim Graham, 7 years ago

Component: UncategorizedDocumentation
Summary: Cannot get diamond multiple inheritance example to workDiamond multiple inheritance example in docs gives a clashing field check error
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

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.

comment:2 by Jeremy Satterfield, 7 years ago

Has patch: set
Owner: changed from nobody to Jeremy Satterfield
Status: newassigned

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.

Version 0, edited 7 years ago by Jeremy Satterfield (next)

comment:3 by Luc Saffre, 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).

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 473ab461:

Fixed #28332 -- Fixed diamond inheritence example in docs.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In e921e98:

[1.11.x] Fixed #28332 -- Fixed diamond inheritence example in docs.

Backport of 473ab4610ef90be05f09127aa37cd20bcda5875e from master

Note: See TracTickets for help on using tickets.
Back to Top