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 , 11 years ago
Cc: | added |
---|---|
Has patch: | set |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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:
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).