Ticket #6074: 6074-queryset-refactor.diff

File 6074-queryset-refactor.diff, 1.7 KB (added by Honza Král, 12 years ago)

fixes the same problem for queryset-refactor branch

  • django/db/models/sql/where.py

     
    4242            return None, []
    4343        result = []
    4444        result_params = []
     45        if self.connection == OR:
     46            failed = 0
    4547        for child in node.children:
    4648            if hasattr(child, 'as_sql'):
    4749                sql, params = child.as_sql(qn=qn)
     
    6062                    if self.connection == AND and not node.negated:
    6163                        # We can bail out early in this particular case (only).
    6264                        raise
     65                    elif self.connection == OR:
     66                        failed += 1
    6367                    sql = None
    6468            if sql:
    6569                result.append(format % sql)
    6670                result_params.extend(params)
     71        if self.connection == OR and failed == len(node.children):
     72            raise EmptyResultSet
    6773        conn = ' %s ' % node.connection
    6874        return conn.join(result), result_params
    6975
  • tests/modeltests/or_lookups/models.py

     
    125125[<Article: Hello>]
    126126>>> Article.objects.complex_filter(Q(pk=1) | Q(pk=2))
    127127[<Article: Hello>, <Article: Goodbye>]
     128
     129# Check that Q(id__in=[]) returns the same results as Q(id__in=[]) | Q(id__in=[]) when used with filter :
     130>>> Article.objects.filter(Q(id__in=[]) | Q(id__in=[]))
     131[]
     132>>> Article.objects.filter(Q(id__in=[]) | Q(id=1) |Q(id__in=[]))
     133[<Article: Hello>]
    128134"""}
Back to Top