#26600: map says a queryset is not iterable
-------------------------------------+-------------------------------------
     Reporter:  ihucos               |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  queryset iterator    |             Triage Stage:
  map                                |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Vitaliy):

 * version:  1.8 => 1.11


Comment:

 I found a way to reproduce the error.

 Class **A** is a simplified version of **QuerySet**
 {{{#!python
 class A(object):

     def __init__(self):
         self._result_cache = None

     def _fetch_all(self):
         if self._result_cache is None:
             self._result_cache = list(self.iterator())

     def iterator(self):
         for x in range(10):
             if x == 5:
                 raise MemoryError  # the type of exception doesn't matter
             yield x

     def __iter__(self):
         self._fetch_all()
         return iter(self._result_cache)
 }}}

 {{{#!python
 In [2]: map(str, A())
 ---------------------------------------------------------------------------
 TypeError                                 Traceback (most recent call
 last)
 /home/user/workspace/project/service/models.pyc in <module>()
 ----> 1 map(str, A())

 TypeError: argument 2 to map() must support iteration
 }}}

 When using python 3:
 {{{#!python
 In [6]: map(str, A())
 ---------------------------------------------------------------------------
 MemoryError                               Traceback (most recent call
 last)
 <ipython-input-6-aad9944017be> in <module>()
 ----> 1 map(str, A())

 <ipython-input-5-4a8af6429c4d> in __iter__(self)
      15
      16         def __iter__(self):
 ---> 17                 self._fetch_all()
      18                 return iter(self._result_cache)
      19

 <ipython-input-5-4a8af6429c4d> in _fetch_all(self)
       6         def _fetch_all(self):
       7                 if self._result_cache is None:
 ----> 8                         self._result_cache = list(self.iterator())
       9
      10         def iterator(self):

 <ipython-input-5-4a8af6429c4d> in iterator(self)
      11                 for x in range(10):
      12                         if x == 5:
 ---> 13                                 raise MemoryError
      14                         yield x
      15

 MemoryError:
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/26600#comment:6>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.7f0fbc340bd6ebe5bc4d74ad45b35961%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to