Ticket #11082: 11082_patch_r10742.git.diff

File 11082_patch_r10742.git.diff, 3.1 KB (added by Clément Nodet, 15 years ago)
  • django/db/models/query.py

    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  
    1313from django.db.models.query_utils import Q, select_related_descend, CollectedObjects, CyclicDependency, deferred_class_factory
    1414from django.db.models import signals, sql
    1515
     16from copy import deepcopy
    1617
    1718# Used to control how many objects are worked with at once in some cases (e.g.
    1819# when deleting objects).
    class QuerySet(object):  
    4041    # PYTHON MAGIC METHODS #
    4142    ########################
    4243
     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       
    4357    def __getstate__(self):
    4458        """
    4559        Allows the QuerySet to be pickled.
  • django/db/models/sql/query.py

    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):  
    16191619                            entry.negate()
    16201620                            self.where.add(entry, AND)
    16211621                            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:
    16231625                    # Leaky abstraction artifact: We have to specifically
    16241626                    # exclude the "foo__in=[]" case from this handling, because
    16251627                    # it's short-circuited in the Where class.
  • tests/regressiontests/queries/models.py

    diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
    index b5fa377..926c2ed 100644
    a b class Plaything(models.Model):  
    271271    def __unicode__(self):
    272272        return self.name
    273273
     274# Simple model for subqueries tests
     275
     276class SimpleSubQuery(models.Model):
     277    name = models.CharField(max_length=10)
     278
     279
    274280
    275281__test__ = {'API_TESTS':"""
    276282>>> generic = NamedCategory.objects.create(name="Generic")
    True  
    11431149>>> r.save()
    11441150>>> Ranking.objects.all()
    11451151[<Ranking: 3: a1>, <Ranking: 2: a2>, <Ranking: 1: a3>]
     1152
     1153Bug #11082 -- when using exclude with an "__in" lookup with a subquery,
     1154that 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
     1159True
     1160
     1161Also, that bug appears when a subquery is used in a "__in" lookup, in a Q
     1162object 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
     1166True
    11461167"""}
    11471168
    11481169# In Python 2.3 and the Python 2.6 beta releases, exceptions raised in __len__
Back to Top