From e12e0e18a4a666c22e119990a495c76079110934 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Sat, 11 Apr 2009 13:20:51 +0000 Subject: Fixed #10197 -- Corrected pickling of querysets when a subset of fields was selected. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10522 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/aggregation_regress/models.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/aggregation_regress/models.py b/tests/regressiontests/aggregation_regress/models.py index a6f99a997d..d1f1451e43 100644 --- a/tests/regressiontests/aggregation_regress/models.py +++ b/tests/regressiontests/aggregation_regress/models.py @@ -1,4 +1,6 @@ # coding: utf-8 +import pickle + from django.db import models from django.conf import settings @@ -242,6 +244,19 @@ FieldError: Cannot resolve keyword 'foo' into field. Choices are: authors, conta >>> Book.objects.filter(id__in=ids) [] +# Regression for #10197 -- Queries with aggregates can be pickled. +# First check that pickling is possible at all. No crash = success +>>> qs = Book.objects.annotate(num_authors=Count('authors')) +>>> out = pickle.dumps(qs) + +# Then check that the round trip works. +>>> query = qs.query.as_sql()[0] +>>> select_fields = qs.query.select_fields +>>> query2 = pickle.loads(pickle.dumps(qs)) +>>> query2.query.as_sql()[0] == query +True +>>> query2.query.select_fields = select_fields + # Regression for #10199 - Aggregate calls clone the original query so the original query can still be used >>> books = Book.objects.all() >>> _ = books.aggregate(Avg('authors__age')) -- cgit v1.3