diff --git a/docs/changelog.rst b/docs/changelog.rst index 9c6e8c8..e732e58 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,12 @@ Changelog ========== +Version 0.5.4 (in development) +------------------------------ + +* Fix ``.non_polymorphic()`` to returns a clone of the queryset, instead of effecting the existing queryset. + + Version 0.5.3 (2013-09-17) -------------------------- diff --git a/polymorphic/query.py b/polymorphic/query.py index 7f6d70d..35d091a 100644 --- a/polymorphic/query.py +++ b/polymorphic/query.py @@ -67,8 +67,9 @@ class PolymorphicQuerySet(QuerySet): """switch off polymorphic behaviour for this query. When the queryset is evaluated, only objects of the type of the base class used for this query are returned.""" - self.polymorphic_disabled = True - return self + qs = self._clone() + qs.polymorphic_disabled = True + return qs def instance_of(self, *args): """Filter the queryset to only include the classes in args (and their subclasses). @@ -109,8 +110,8 @@ class PolymorphicQuerySet(QuerySet): """translate the polymorphic field paths in the kwargs, then call vanilla aggregate. We need no polymorphic object retrieval for aggregate => switch it off.""" self._process_aggregate_args(args, kwargs) - self.polymorphic_disabled = True - return super(PolymorphicQuerySet, self).aggregate(*args, **kwargs) + qs = self.non_polymorphic() + return super(PolymorphicQuerySet, qs).aggregate(*args, **kwargs) # Since django_polymorphic 'V1.0 beta2', extra() always returns polymorphic results.^ # The resulting objects are required to have a unique primary key within the result set