diff --git a/django/db/models/query.py b/django/db/models/query.py
index 2e02f3f..b61c7cd 100644
a
|
b
|
from django.db.models.fields import DateField
|
13 | 13 | from django.db.models.query_utils import Q, select_related_descend, CollectedObjects, CyclicDependency, deferred_class_factory |
14 | 14 | from django.db.models import signals, sql |
15 | 15 | |
| 16 | from copy import deepcopy |
16 | 17 | |
17 | 18 | # Used to control how many objects are worked with at once in some cases (e.g. |
18 | 19 | # when deleting objects). |
… |
… |
class QuerySet(object):
|
40 | 41 | # PYTHON MAGIC METHODS # |
41 | 42 | ######################## |
42 | 43 | |
| 44 | def __deepcopy__(self, memo): |
| 45 | """ |
| 46 | Deep copying of a QuerySet without |
| 47 | populating the cache |
| 48 | """ |
| 49 | obj_dict = deepcopy(self.__dict__, memo) |
| 50 | obj_dict['_iter'] = None |
| 51 | |
| 52 | obj = self.__class__() |
| 53 | obj.__dict__.update(obj_dict) |
| 54 | return obj |
| 55 | |
| 56 | |
43 | 57 | def __getstate__(self): |
44 | 58 | """ |
45 | 59 | Allows the QuerySet to be pickled. |
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 394e30b..c6472b0 100644
a
|
b
|
class BaseQuery(object):
|
1619 | 1619 | entry.negate() |
1620 | 1620 | self.where.add(entry, AND) |
1621 | 1621 | break |
1622 | | elif not (lookup_type == 'in' and not value) and field.null: |
| 1622 | elif not (lookup_type == 'in' and |
| 1623 | (not hasattr(value, 'as_sql') and not hasattr(value, '_as_sql') and |
| 1624 | not value)) and field.null: |
1623 | 1625 | # Leaky abstraction artifact: We have to specifically |
1624 | 1626 | # exclude the "foo__in=[]" case from this handling, because |
1625 | 1627 | # it's short-circuited in the Where class. |
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index b5fa377..926c2ed 100644
a
|
b
|
class Plaything(models.Model):
|
271 | 271 | def __unicode__(self): |
272 | 272 | return self.name |
273 | 273 | |
| 274 | # Simple model for subqueries tests |
| 275 | |
| 276 | class SimpleSubQuery(models.Model): |
| 277 | name = models.CharField(max_length=10) |
| 278 | |
| 279 | |
274 | 280 | |
275 | 281 | __test__ = {'API_TESTS':""" |
276 | 282 | >>> generic = NamedCategory.objects.create(name="Generic") |
… |
… |
True
|
1143 | 1149 | >>> r.save() |
1144 | 1150 | >>> Ranking.objects.all() |
1145 | 1151 | [<Ranking: 3: a1>, <Ranking: 2: a2>, <Ranking: 1: a3>] |
| 1152 | |
| 1153 | Bug #11082 -- when using exclude with an "__in" lookup with a subquery, |
| 1154 | that subquery gets executed beforehand |
| 1155 | >>> subq = SimpleSubQuery.objects.all() |
| 1156 | >>> qs = SimpleSubQuery.objects.exclude(pk__in=subq) |
| 1157 | >>> _ = list(qs) |
| 1158 | >>> subq._result_cache is None |
| 1159 | True |
| 1160 | |
| 1161 | Also, that bug appears when a subquery is used in a "__in" lookup, in a Q |
| 1162 | object which is a left hand operand on a & or | expression |
| 1163 | >>> subq = SimpleSubQuery.objects.all() |
| 1164 | >>> q_obj = Q(pk__in=subq) & Q(name='aa') |
| 1165 | >>> subq._result_cache is None |
| 1166 | True |
1146 | 1167 | """} |
1147 | 1168 | |
1148 | 1169 | # In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__ |