Opened 5 years ago

Closed 5 years ago

Last modified 5 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 Changed 5 years ago by Tim Graham

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 Changed 5 years ago by Jeremy Satterfield

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 5 years ago by Jeremy Satterfield (next)

comment:3 Changed 5 years ago by Luc Saffre

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 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 473ab461:

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

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

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