Opened 5 years ago

Closed 5 years ago

#20814 closed Bug (fixed)

model validation: misleading error message with model inheritance

Reported by: Shai Berger Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords: model-validation check
Cc: chris.medrela+djangotrac@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Consider this little set of models. The idea is that there are "general" objects, but some of them are special: Each of the special objects holds pointers to other objects.

    class General(models.Model):
        name = models.CharField(max_length=30)

    class Special(General):

    class SpecialDetail(models.Model):
        parent = models.ForeignKey(Special)
        target = models.ForeignKey(General)

Model validation fails (as it should), but the error message is

specialdetail: accessor for field 'parent' clashes with 'Special.specialdetail_set'

when in fact the clash is with General.specialdetail_set generated by the target field (and inherited by Special). Of course, when isolated like this, it is very easy to spot where the real problem is, but when the models have a little more content in them, this can be (and actually was) quite perplexing.

Change History (2)

comment:1 Changed 5 years ago by chrismedrela

Cc: chris.medrela+djangotrac@… added
Has patch: set
Triage Stage: UnreviewedAccepted

I've created a patch (see the pull request: The misleading error messages were changed into something like this:

Accessor for field 'parent' clashes with accessor for field ''.

I did the same in my branch where I'm working at my Google Summer of Code 2013 project (revamping system checks framework -- see discussion at django-developers:!topic/django-developers/fEf21dtpqDE).

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

Resolution: fixed
Status: newclosed

In 32a962bdbfb187ad884273cdbc02e8b0dbb692e6:

Fixed #20814 -- Improved model field accessor clash error messages

Thanks shai for the suggestion.

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