Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17668 - prefetch_related does not work in in_bulk

Thanks to gurets for the report, and akaariai for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17600 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit de9942a6673cfbe442abdfabc1e8f7c0a652ef5b 1 parent 4b641b7
Luke Plant authored February 28, 2012
2  django/db/models/query.py
@@ -485,7 +485,7 @@ def in_bulk(self, id_list):
485 485
         qs = self._clone()
486 486
         qs.query.add_filter(('pk__in', id_list))
487 487
         qs.query.clear_ordering(force_empty=True)
488  
-        return dict([(obj._get_pk_val(), obj) for obj in qs.iterator()])
  488
+        return dict([(obj._get_pk_val(), obj) for obj in qs])
489 489
 
490 490
     def delete(self):
491 491
         """
6  docs/ref/models/querysets.txt
@@ -871,6 +871,9 @@ could be generated, which, depending on the database, might have performance
871 871
 problems of its own when it comes to parsing or executing the SQL query. Always
872 872
 profile for your use case!
873 873
 
  874
+Note that if you use ``iterator()`` to run the query, ``prefetch_related()``
  875
+calls will be ignored since these two optimizations do not make sense together.
  876
+
874 877
 extra
875 878
 ~~~~~
876 879
 
@@ -1430,6 +1433,9 @@ performance and a significant reduction in memory.
1430 1433
 Note that using ``iterator()`` on a ``QuerySet`` which has already been
1431 1434
 evaluated will force it to evaluate again, repeating the query.
1432 1435
 
  1436
+Also, use of ``iterator()`` causes previous ``prefetch_related()`` calls to be
  1437
+ignored since these two optimizations do not make sense together.
  1438
+
1433 1439
 latest
1434 1440
 ~~~~~~
1435 1441
 
13  tests/modeltests/prefetch_related/tests.py
@@ -470,3 +470,16 @@ def test_prefetch_nullable(self):

0 notes on commit de9942a

Please sign in to comment.
Something went wrong with that request. Please try again.