On Mon, Jan 3, 2011 at 6:16 PM, Margie Roginski <[email protected]>wrote:

> I find that if I filter by ORing an empty Q() with a non-empty Q()
> that I don't get the expected result.  I would expect that this should
> return all objects of the specified model that the empty Q() would
> return.  Let me use an example to be more clear:
>
> I have a single Task object with its name set to foo.
>
> Task.objects.filter(Q()) gives me that one object:
> [<Task: foo>]
>
> But:
>
> Task.objects.filter(Q()|Q(name="bar"))
>
> returns []
>
> Is this a bug or am I misunderstanding something?  This is on Django
> 1.2.1
>
>
Near as I can tell the doc doesn't say anything about what effect an empty
Q() is supposed to have, so I don't know if the behavior you describe is a
bug or not.

However, the behavior you describe makes sense to me if you take the view
that and empty Q() just doesn't apply any conditions to the query, and
generates no SQL. Similarly combining it with another Q generates no SQL, so
you are left with the other Q results.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to