From 0a809df4da3c714f0ba4b327028e96c9dc0e17a5 Mon Sep 17 00:00:00 2001 From: Hanley Date: Fri, 23 Jun 2017 09:51:32 -0400 Subject: [PATCH 1/2] make InheritanceIterable inherit from ModelIterable instead of BaseIterable --- AUTHORS.rst | 1 + model_utils/managers.py | 4 ++-- tests/test_inheritance_iterable.py | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/test_inheritance_iterable.py diff --git a/AUTHORS.rst b/AUTHORS.rst index 4dd3044..fd350c0 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -15,6 +15,7 @@ Facundo Gaich Felipe Prenholato Filipe Ximenes Gregor Müllegger +Hanley Hansen ivirabyan James Oakley Jannis Leidel diff --git a/model_utils/managers.py b/model_utils/managers.py index 9dc68a2..8e022b4 100644 --- a/model_utils/managers.py +++ b/model_utils/managers.py @@ -7,14 +7,14 @@ try: from django.db.models.query import BaseIterable, ModelIterable except ImportError: # Django 1.8 does not have iterable classes - BaseIterable = object + BaseIterable, ModelIterable = object, object from django.core.exceptions import ObjectDoesNotExist from django.db.models.constants import LOOKUP_SEP from django.utils.six import string_types -class InheritanceIterable(BaseIterable): +class InheritanceIterable(ModelIterable): def __iter__(self): queryset = self.queryset iter = ModelIterable(queryset) diff --git a/tests/test_inheritance_iterable.py b/tests/test_inheritance_iterable.py new file mode 100644 index 0000000..884b763 --- /dev/null +++ b/tests/test_inheritance_iterable.py @@ -0,0 +1,22 @@ +from __future__ import unicode_literals + +from unittest import skipIf + +import django +from django.test import TestCase +from django.db.models import Prefetch + +from tests.models import InheritanceManagerTestParent, InheritanceManagerTestChild1 + + +class InheritanceIterableTest(TestCase): + @skipIf(django.VERSION[:2] == (1, 10), "Django 1.10 expects ModelIterable not a subclass of it") + def test_prefetch(self): + qs = InheritanceManagerTestChild1.objects.all().prefetch_related( + Prefetch( + 'normal_field', + queryset=InheritanceManagerTestParent.objects.all(), + to_attr='normal_field_prefetched' + ) + ) + self.assertEquals(qs.count(), 0) From 8c935d3a83b5689975b800e69c80baed0ac229d3 Mon Sep 17 00:00:00 2001 From: Hanley Date: Fri, 23 Jun 2017 09:56:51 -0400 Subject: [PATCH 2/2] update changes.rst --- CHANGES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index a578c65..b85dcaf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,8 @@ CHANGES master (unreleased) ------------------- +* Update InheritanceIterable to inherit from + ModelIterable instead of BaseIterable, fixes GH-277. 3.0.0 (2017.04.13) ------------------