#7908 closed (fixed)
A ForeignKey of an abstract class can fail to validate
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ForeignKey abstract | |
Cc: | mk@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A model with a ForeignKey relating to an abstract class fails to validate by crashing in related.py line 605.
The example models.py is attached or see: http://dpaste.com/66858/
The traceback from manage.py validate: http://dpaste.com/66860/
Attachments (3)
Change History (8)
by , 16 years ago
comment:1 by , 16 years ago
I tried adding a guard by replacing the offending line 605 as follows:
to_field = to_field
if to_field == None:
if to._meta.pk is None:
raise ValueError("The %s model does not have a primary key and therefore a ForeignKey cannot relate to it." % to_name)
to_field = to._meta.pk.name
This is not a real fix as the validate command still crashes, but the error message is a bit nicer. A real fix has to go in the validate code.
by , 16 years ago
by , 16 years ago
Attachment: | 7908.patch added |
---|
comment:2 by , 16 years ago
Cc: | added |
---|---|
Has patch: | set |
Triage Stage: | Unreviewed → Ready for checkin |
The attached patch gives a better(?) error message for both ForeignKey and ManyToManyField, using the syntax above and also using f.e. mine = models.ManyToManyField('Attachment') (lazy loading)
comment:3 by , 16 years ago
milestone: | → 1.0 |
---|
comment:4 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
a models.py file that fails during validation