Queryset unions... Is that a bug?

3 views
Skip to first unread message

Julien

unread,
Dec 21, 2007, 12:11:31 AM12/21/07
to Django users
Hi,

I've been struggling with union-ing querysets. Here's an example:

>>> qs1=User.objects.filter(........)
>>> qs1=User.objects.filter(........)
>>> qs1
[<User: john>]
>>> qs2
[]
>>> qs1 | qs2
[]
>>> qs1 or qs2
[<User: john>]

I thought that "|" was equivalent to a "or", as mentioned in the doc:
http://www.djangoproject.com/documentation/db-api/#complex-lookups-with-q-objects

I'm fairly new to Django, but this look like a bug to me. Is that so?

Thanks!

Julien

Malcolm Tredinnick

unread,
Dec 21, 2007, 12:24:57 AM12/21/07
to django...@googlegroups.com

Yeah, it's a bug. See, for example, tickets #2080 and #2253. They're
fixed on the queryset-refactor branch, so will be merged into trunk when
that's done.

Regards,
Malcolm

--
What if there were no hypothetical questions?
http://www.pointy-stick.com/blog/

Julien

unread,
Dec 21, 2007, 12:33:57 AM12/21/07
to Django users
Thanks for the hint!

This is not the first time that I stumble on the fact that the
documentation is ahead of the code. And that's very problematic
because you spend hours trying to understand why it doesn't work as
the doc says, while it's in fact a bug in the code or a feature that
hasn't been merged in the trunk yet...

Cheers!

Julien

On Dec 21, 4:24 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Thu, 2007-12-20 at 21:11 -0800, Julien wrote:
> > Hi,
>
> > I've been struggling with union-ing querysets. Here's an example:
>
> > >>> qs1=User.objects.filter(........)
> > >>> qs1=User.objects.filter(........)
> > >>> qs1
> > [<User: john>]
> > >>> qs2
> > []
> > >>> qs1 | qs2
> > []
> > >>> qs1 or qs2
> > [<User: john>]
>
> > I thought that "|" was equivalent to a "or", as mentioned in the doc:
> >http://www.djangoproject.com/documentation/db-api/#complex-lookups-wi...

Malcolm Tredinnick

unread,
Dec 21, 2007, 1:14:42 AM12/21/07
to django...@googlegroups.com

On Thu, 2007-12-20 at 21:33 -0800, Julien wrote:
> Thanks for the hint!
>
> This is not the first time that I stumble on the fact that the
> documentation is ahead of the code. And that's very problematic
> because you spend hours trying to understand why it doesn't work as
> the doc says, while it's in fact a bug in the code or a feature that
> hasn't been merged in the trunk yet...

The documentation isn't in front of the code; that would be horrendously
unfair to our users. Sometimes bugs creep in though. Creating "or" joins
of querysets works sometimes and fails in some particular cases. These
things get fixed when we discover them.

Malcolm

--
Quantum mechanics: the dreams stuff is made of.
http://www.pointy-stick.com/blog/

Reply all
Reply to author
Forward
0 new messages