Get tests running on django 1.11

I'm a little concerned that this loses some of the efficiencies (in
particular, chunking) from previous versions. That's something that can
probably be improved.
fix_request_path_info
Charlie Denton 2017-04-12 23:52:06 +01:00
parent a568c04e40
commit f010c6ddf7
No known key found for this signature in database
GPG Key ID: 5BBA1783DA191613
1 changed files with 61 additions and 37 deletions

View File

@ -25,6 +25,25 @@ except ImportError:
Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE Polymorphic_QuerySet_objects_per_request = CHUNK_SIZE
if django.VERSION >= (1, 9):
# We ignore this on django < 1.9, as ModelIterable didn't yet exist.
from django.db.models.query import ModelIterable
class PolymorphicModelIterable(ModelIterable):
def __iter__(self):
base_iter = super(PolymorphicModelIterable, self).__iter__()
if self.queryset.polymorphic_disabled:
for o in base_iter:
yield o
return
real_instances = self.queryset._get_real_instances(base_iter)
for obj in real_instances:
yield obj
def transmogrify(cls, obj): def transmogrify(cls, obj):
""" """
Upcast a class to a different type without asking questions. Upcast a class to a different type without asking questions.
@ -72,6 +91,9 @@ class PolymorphicQuerySet(QuerySet):
# to that queryset as well). # to that queryset as well).
self.polymorphic_deferred_loading = (set([]), True) self.polymorphic_deferred_loading = (set([]), True)
super(PolymorphicQuerySet, self).__init__(*args, **kwargs) super(PolymorphicQuerySet, self).__init__(*args, **kwargs)
if django.VERSION >= (1, 9):
# On django < 1.9 we override the iterator() method instead
self._iterable_class = PolymorphicModelIterable
def _clone(self, *args, **kwargs): def _clone(self, *args, **kwargs):
# Django's _clone only copies its own variables, so we need to copy ours here # Django's _clone only copies its own variables, so we need to copy ours here
@ -407,6 +429,8 @@ class PolymorphicQuerySet(QuerySet):
return resultlist return resultlist
if django.VERSION < (1, 9):
# On django 1.9+, we can define self._iterator_class instead of iterator()
def iterator(self): def iterator(self):
""" """
This function is used by Django for all object retrieval. This function is used by Django for all object retrieval.