--
Ticket URL: <https://code.djangoproject.com/ticket/17930>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* 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>
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:2>
Comment (by akaariai):
What should the expected output be? Maybe (pseudoquery):
{{{
select * from example
where (original_query_conditions) or pk in (select pk from example where
public = false order by random() limit 1)
}}}
Or, in this special case this could be written as:
{{{
select * from example
where (original_query_conditions) or pk = (select pk from example where
public = false order by random() limit 1)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:3>
Comment (by anonymous):
Expected:
{{{
>> query = query | Example.objects.filter(public =
False).order_by('?')[:1]
>> print query.count()
3
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:4>
* owner: nobody => Ian Foote
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:5>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:6>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:7>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e1fc07c047f8e46c2cea0120f44011fc458f1e91" e1fc07c]:
{{{
#!CommitTicketReference repository=""
revision="e1fc07c047f8e46c2cea0120f44011fc458f1e91"
Fixed #17930 -- Allowed ORing (|) with sliced QuerySets.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:9>