Opened 10 years ago
Closed 10 years ago
#23443 closed Cleanup/optimization (fixed)
Inconsistent FieldError message under some circumstances
Reported by: | Thomas C | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | 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
Under some circumstances, FieldError
are raised with inconsistent messages Cannot resolve keyword u'name' into field. Choices are: name, ...
Reproduced with the following code :
# Model class Tag(models.Model): name = models.CharField(max_length=10) parent = models.ForeignKey('self', blank=True, null=True, related_name='children') category = models.ForeignKey(NamedCategory, null=True, default=None) # FieldError Tag.objects.values_list('name__foo')
Change History (6)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
Hi,
I agree that we should try and improve the message.
However, your proposed patch now generates the following message:
Cannot resolve keyword 'foo' into field. Choices are: category, category_id, children, id, name, parent, parent_id
I'm not sure if that's an improvement since this message seems to indicate that doing name__category
would be valid.
Instead, I think the error message should say that name
is not a field you can "jump" with the double underscore syntax (I'm not sure what the correct term for that is).
Looking at the code, this will probably require some more in-depth changes since the exit condition of the loop conflates non-existing field names and fields that can't be "jumped".
Thanks.
comment:5 by , 10 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Don't forget to uncheck "Patch needs improvement" so the ticket appears in the review queue. The patch looks okay to me, but would be good to have another review from an ORM expert to make sure nothing has been overlooked.
comment:6 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Proposed patch https://github.com/django/django/pull/3188