Opened 8 years ago

Closed 8 years ago

#6664 closed (fixed)

Strange effect of invalid ordering in qs-rf

Reported by: Petr Marhoun <petr.marhoun@…> 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: UI/UX:

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

Change History (2)

comment:1 Changed 8 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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.)

comment:2 Changed 8 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [7163]

Note: See TracTickets for help on using tickets.
Back to Top