#22349: RawQuerySet doesn't implement __len__, __bool__
-------------------------------------+-------------------------------------
     Reporter:  cdestigter           |                    Owner:
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |               Resolution:
     Severity:  Normal               |             Triage Stage:  Accepted
     Keywords:                       |      Needs documentation:  0
    Has patch:  0                    |  Patch needs improvement:  0
  Needs tests:  0                    |                    UI/UX:  0
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by loic84):

 Dunno if it's by design, but `RawQuerySet` and  `QuerySet` operate vastly
 differently as there is no such thing as an "evaluated" `RawQuerySet`:

 {{{
 list(queryset)
 with assertNumQueries(1)
     for i in range(10):
         queryset[0]

 list(raw_queryset)
 with assertNumQueries(10)
     for i in range(10):
         raw_queryset[0]
 }}}

 This fundamental difference makes having a shared ancestor impractical.

 With that in mind, I think adding `__len__` would be a nasty footgun, if
 you only want the number of rows, you can write a `COUNT` SQL query, if
 you want the count and the result, then you should definitely store the
 result in a list to avoid a second query.

 Of course we could make `RawQuerySet` maintain an internal cache akin to
 `QuerySet`, but that'd have to be a ticket in its own right.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22349#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.3256cfb86d962b16647d00727eba58c3%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to