From 25130b9675e5a53926ad45d828460341679d49fe Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Thu, 2 Apr 2009 01:49:12 +0000 Subject: [PATCH] Fixed #10670: fixed reusing QuerySets previously used in a filter expression. Thanks, Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10357 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/models/sql/query.py | 3 +-- .../aggregation_regress/models.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index ce732b1046d..4735fdabbb5 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -196,7 +196,7 @@ class BaseQuery(object): obj.distinct = self.distinct obj.select_related = self.select_related obj.related_select_cols = [] - obj.aggregates = self.aggregates.copy() + obj.aggregates = deepcopy(self.aggregates) if self.aggregate_select_mask is None: obj.aggregate_select_mask = None else: @@ -2366,4 +2366,3 @@ def add_to_dict(data, key, value): data[key].add(value) else: data[key] = set([value]) - diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py index 275ea073901..2dfa1818fce 100644 --- a/tests/regressiontests/aggregation_regress/models.py +++ b/tests/regressiontests/aggregation_regress/models.py @@ -259,6 +259,23 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta >>> Book.objects.annotate(Count('publisher')).values('publisher').count() 6 +>>> publishers = Publisher.objects.filter(id__in=(1,2)) +>>> publishers +[, ] + +>>> publishers = publishers.annotate(n_books=models.Count('book')) +>>> publishers[0].n_books +2 + +>>> publishers +[, ] + +>>> books = Book.objects.filter(publisher__in=publishers) +>>> books +[, , ] + +>>> publishers +[, ] """ } @@ -307,4 +324,3 @@ if settings.DATABASE_ENGINE != 'sqlite3': """ -