﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15239	when I combine two Q objects with | operator it ends up with AND being used in sql query.	muaddib@…	nobody	"Hello. I created two querysets which works fine.
{{{
Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(Q(mysum__lte=F('invoice_total')) )
Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(mysum=None)
}}}
queryset1 returns objects with mysum less then invoice_total. mysum sums payments for the particular invoice. 
queryset2 catches non-numeric objects with 'None' as mysum value. This happens when there no payments for the particular invoice.

Fields used:
invoice_total is a decimal field.
payments!__payment is also decimal (in related_set).

Now to combine those two querysets into one i use Q logic. 
{{{
Invoice.objects.annotate(mysum=Sum('payments__payment')).filter(Q(mysum=None) | Q(mysum__lte=F('invoice_total')) )
}}}

Unfortunatly it doesnt work (returned queryset is empty). In sql log i can see that those two conditions above are always being glued with default AND (should be ORed because I use Q | Q, not Q & Q).

Database is a postresql 8.3.

"		closed	Database layer (models, ORM)	1.2		duplicate			Unreviewed	0	0	0	0	0	0
