model validation: misleading error message with model inheritance
|Reported by:||shai||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||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): 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 Changed 21 months ago by chrismedrela
- Cc chris.medrela+djangotrac@… added
- Has patch set
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted