Django

Code

Ticket #6664 (closed: fixed)

Opened 9 months ago

Last modified 9 months ago

Strange effect of invalid ordering in qs-rf

Reported by: Petr Marhoun <petr.marhoun@gmail.com> Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: queryset-refactor Keywords: qs-rf
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Attachments

Change History

02/26/08 18:39:18 changed by mtredinnick

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

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

02/26/08 19:42:50 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [7163]


Add/Change #6664 (Strange effect of invalid ordering in qs-rf)




Change Properties
Action