Ticket #6074: patch.diff

File patch.diff, 1.5 KB (added by Raphaël Braud, 11 years ago)
  • django/db/models/query.py

     
    714714
    715715    def get_sql(self, opts):
    716716        joins, where, params = SortedDict(), [], []
    717         for val in self.args:
     717        for val in self.args[:-1]:
    718718            try:
    719719                joins2, where2, params2 = val.get_sql(opts)
    720720                joins.update(joins2)
    721721                where.extend(where2)
    722722                params.extend(params2)
    723723            except EmptyResultSet:
    724                 if not isinstance(self, QOr):
     724                if not(isinstance(self, QOr)):
    725725                    raise EmptyResultSet
     726        joins2, where2, params2 = self.args[-1].get_sql(opts)
     727        joins.update(joins2)
     728        where.extend(where2)
     729        params.extend(params2)
    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(id__in=[]) returns the same results as Q(id__in=[]) | Q(id__in=[]) when used with filter :
     121>>> Article.objects.filter(Q(id__in=[]) | Q(id__in=[]))
     122[]
    119123"""}
Back to Top