diff options
| author | Luke Plant <L.Plant.98@cantab.net> | 2012-02-28 19:34:04 +0000 |
|---|---|---|
| committer | Luke Plant <L.Plant.98@cantab.net> | 2012-02-28 19:34:04 +0000 |
| commit | de9942a6673cfbe442abdfabc1e8f7c0a652ef5b (patch) | |
| tree | 4672c363db7cbb1b81ea533be2b00b0ce25129f0 /tests | |
| parent | 4b641b78fa1e9cf774d1c0339ef07a854c35e011 (diff) | |
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
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/prefetch_related/tests.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/modeltests/prefetch_related/tests.py b/tests/modeltests/prefetch_related/tests.py index 4c51a83bd9..382aed68b4 100644 --- a/tests/modeltests/prefetch_related/tests.py +++ b/tests/modeltests/prefetch_related/tests.py @@ -470,3 +470,16 @@ class NullableTest(TestCase): for e in qs2] self.assertEqual(co_serfs, co_serfs2) + + def test_in_bulk(self): + """ + In-bulk does correctly prefetch objects by not using .iterator() + directly. + """ + boss1 = Employee.objects.create(name="Peter") + boss2 = Employee.objects.create(name="Jack") + with self.assertNumQueries(2): + # Check that prefetch is done and it does not cause any errors. + bulk = Employee.objects.prefetch_related('serfs').in_bulk([boss1.pk, boss2.pk]) + for b in bulk.values(): + list(b.serfs.all()) |
