Ticket #6074: 6074_2.diff

File 6074_2.diff, 1.6 KB (added by Raphaël Braud, 17 years ago)
  • django/db/models/query.py

     
    714714
    715715    def get_sql(self, opts):
    716716        joins, where, params = SortedDict(), [], []
     717        failed = 0
    717718        for val in self.args:
    718719            try:
    719720                joins2, where2, params2 = val.get_sql(opts)
     
    721722                where.extend(where2)
    722723                params.extend(params2)
    723724            except EmptyResultSet:
    724                 if not isinstance(self, QOr):
    725                     raise EmptyResultSet
     725                failed+=1
     726        if len(self.args)==failed:
     727            raise EmptyResultSet
     728        if not isinstance(self, QOr) and failed:
     729            raise EmptyResultSet
    726730        if where:
    727731            return joins, ['(%s)' % self.operator.join(where)], params
    728732        return joins, [], params
  • tests/modeltests/or_lookups/models.py

     
    116116[<Article: Hello>]
    117117>>> Article.objects.complex_filter(Q(pk=1) | Q(pk=2))
    118118[<Article: Hello>, <Article: Goodbye>]
     119
     120# Check that Q(pk__in=[]) returns the same results as Q(pk__in=[]) | Q(pk__in=[]) when used with filter :
     121>>> Article.objects.filter(Q(pk__in=[]) | Q(pk__in=[]))
     122[]
     123
     124# But with Q(pk__in=[]) | Q(pk__in=[1,]) | Q(pk__in=[]) it must return something :
     125>>> Article.objects.filter(Q(pk__in=[]) | Q(pk__in=[1,]) | Q(pk__in=[]))
     126[<Article: Hello>]
     127
    119128"""}
Back to Top