Opened 11 years ago

Closed 11 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: dev
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

Description

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):
        pass

    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 by chrismedrela, 11 years ago

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

I've created a patch (see the pull request: https://github.com/django/django/pull/1440). The misleading error messages were changed into something like this:

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

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: https://groups.google.com/forum/#!topic/django-developers/fEf21dtpqDE).

comment:2 by Tim Graham <timograham@…>, 11 years ago

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