Message info
 
To: From:Django Subject:Re: [Django] #17930: Error in Queryset with operator | (union queryset) + slice Date:Sun, 18 Mar 2012 16:02:19 -0000
 

#17930: Error in Queryset with operator | (union queryset) + slice
-------------------------------------+-------------------------------------
Reporter: vini.gracindo@ | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.3
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: queryset union, | Unreviewed
slice | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by lrekucki):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> {{{
> class Example:
> name = models.CharField(max_length = 30)
> public = models.BooleanField()
> }}}
>
> >>> Example.objects.create('example 1', False)
> <Example: Example object>
> >>> Example.objects.create('example 2', False)
> <Example: Example object>
> >>> Example.objects.create('example 3', True)
> <Example: Example object>
> >>> Example.objects.create('example 4', True)
> <Example: Example object>
> >>> Example.objects.create('example 5', False)
> <Example: Example object>
> >>> query = Example.objects.filter(public = True)
> >>> if(query.count() < 3):
> ... query = query | Example.objects.filter(public =
> False).order_by('?')[:1]
> ...
> >>> query.count()
> 5
> >>>
>
> When using the union of querysets to slice it "ignores" the slice and
> takes all objects where public = false.

New description:

{{{
class Example:
name = models.CharField(max_length = 30)
public = models.BooleanField()
}}}

{{{
>>> Example.objects.create('example 1', False)
<Example: Example object>
>>> Example.objects.create('example 2', False)
<Example: Example object>
>>> Example.objects.create('example 3', True)
<Example: Example object>
>>> Example.objects.create('example 4', True)
<Example: Example object>
>>> Example.objects.create('example 5', False)
<Example: Example object>
>>> query = Example.objects.filter(public = True)
>>> if(query.count() < 3):
... query = query | Example.objects.filter(public =
False).order_by('?')[:1]
...
>>> query.count()
5
>>>
}}}

When using the union of querysets to slice it "ignores" the slice and
takes all objects where {{{public = false}}}.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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