Ticket #6074: 6074.diff
| File 6074.diff, 2.3 kB (added by Honza_Kral, 7 months ago) |
|---|
-
a/django/db/models/query.py
old new 715 715 def get_sql(self, opts): 716 716 joins, where, params = SortedDict(), [], [] 717 717 for val in self.args: 718 try: 719 joins2, where2, params2 = val.get_sql(opts) 720 joins.update(joins2) 721 where.extend(where2) 722 params.extend(params2) 723 except EmptyResultSet: 724 if not isinstance(self, QOr): 725 raise EmptyResultSet 718 joins2, where2, params2 = val.get_sql(opts) 719 joins.update(joins2) 720 where.extend(where2) 721 params.extend(params2) 726 722 if where: 727 723 return joins, ['(%s)' % self.operator.join(where)], params 728 724 return joins, [], params … … 743 739 744 740 class QOr(QOperator): 745 741 "Encapsulates a combined query that uses 'OR'." 742 def get_sql(self, opts): 743 joins, where, params = SortedDict(), [], [] 744 failed = 0 745 for val in self.args: 746 try: 747 joins2, where2, params2 = val.get_sql(opts) 748 joins.update(joins2) 749 where.extend(where2) 750 params.extend(params2) 751 except EmptyResultSet: 752 failed += 1 753 if failed == len( self.args ): 754 raise EmptyResultSet 755 756 if where: 757 return joins, ['(%s)' % self.operator.join(where)], params 758 return joins, [], params 746 759 operator = ' OR ' 747 760 def __and__(self, other): 748 761 return QAnd(self, other) -
a/tests/modeltests/or_lookups/models.py
old new 116 116 [<Article: Hello>] 117 117 >>> Article.objects.complex_filter(Q(pk=1) | Q(pk=2)) 118 118 [<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 [] 123 >>> Article.objects.filter(Q(id__in=[]) | Q(id=1) |Q(id__in=[])) 124 [<Article: Hello>] 119 125 """}
