﻿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
15240	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:[[BR]]
invoice_total is a decimal field.[[BR]]
payment is a related_set relation which holds a decimal, too.[[BR]]

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		worksforme		alejandroalonsofernandez@…	Unreviewed	0	0	0	0	0	0
