Opened 17 years ago
Closed 17 years ago
#6664 closed (fixed)
Strange effect of invalid ordering in qs-rf
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | queryset-refactor |
Severity: | Keywords: | qs-rf | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have tried very simple model (with 20 objects):
class A(models.Model): value = models.IntegerField()
And this code:
>>> A.objects.count() 20 >>> len(list(A.objects.order_by('value'))) 20 >>> len(list(A.objects.order_by('nonsense'))) # Should it be an exception? 0 >>> A.objects.order_by('nonsense') TypeError: Cannot resolve keyword 'nonsense' into field. Choices are: id, value
Note:
See TracTickets
for help on using tickets.
This is a cool error: when calling list(), Python tries to work with pre-iterator-protocol objects as well. Which means it quietly swallows TypeError (only). Sadly, that was precisely the exception we were raising in this case. I'm going to change the exception type to something less confusing. (Thanks to Jacob for guessing what was going wrong here.)