[Django] #17930: Error in Queryset with operator | (union queryset) + slice

15 views
Skip to first unread message

Django

unread,
Mar 18, 2012, 11:31:05 AM3/18/12
to django-...@googlegroups.com
#17930: Error in Queryset with operator | (union queryset) + slice
----------------------------------------------+----------------------------
Reporter: vini.gracindo@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.3
Severity: Normal | Keywords: queryset
Triage Stage: Unreviewed | union, slice
Easy pickings: 0 | Has patch: 0
| UI/UX: 0
----------------------------------------------+----------------------------
{{{
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 18, 2012, 12:02:19 PM3/18/12
to django-...@googlegroups.com
#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

unread,
May 11, 2012, 12:56:50 PM5/11/12
to django-...@googlegroups.com
#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: Accepted
Keywords: queryset union, | Needs documentation: 0
slice | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by lukeplant):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:2>

Django

unread,
May 11, 2012, 1:07:46 PM5/11/12
to django-...@googlegroups.com
#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: Accepted
Keywords: queryset union, | Needs documentation: 0
slice | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

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>

Django

unread,
May 11, 2012, 1:25:07 PM5/11/12
to django-...@googlegroups.com
#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: Accepted
Keywords: queryset union, | Needs documentation: 0
slice | Patch needs improvement: 0
Has patch: 0 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 0 |
-------------------------------------+-------------------------------------

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>

Django

unread,
Nov 13, 2018, 3:27:26 PM11/13/18
to django-...@googlegroups.com
#17930: Error in Queryset with operator | (union queryset) + slice
-------------------------------------+-------------------------------------
Reporter: vini.gracindo@… | Owner: Ian Foote
Type: Bug | Status: assigned

Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution:
Keywords: queryset union, | Triage Stage: Accepted
slice |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian Foote):

* owner: nobody => Ian Foote
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:5>

Django

unread,
Nov 13, 2018, 4:05:25 PM11/13/18
to django-...@googlegroups.com
#17930: Error in Queryset with operator | (union queryset) + slice
-------------------------------------+-------------------------------------
Reporter: vini.gracindo@… | Owner: Ian Foote
Type: Bug | Status: assigned
Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution:
Keywords: queryset union, | Triage Stage: Accepted
slice |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ian Foote):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:6>

Django

unread,
Nov 13, 2018, 4:37:39 PM11/13/18
to django-...@googlegroups.com
#17930: Error in Queryset with operator | (union queryset) + slice
-------------------------------------+-------------------------------------
Reporter: vini.gracindo@… | Owner: Ian Foote
Type: Bug | Status: assigned
Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution:
Keywords: queryset union, | Triage Stage: Accepted
slice |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:7>

Django

unread,
Nov 14, 2018, 5:51:49 PM11/14/18
to django-...@googlegroups.com
#17930: Error in Queryset with operator | (union queryset) + slice
-------------------------------------+-------------------------------------
Reporter: vini.gracindo@… | Owner: Ian Foote
Type: Bug | Status: assigned
Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution:
Keywords: queryset union, | Triage Stage: Ready for
slice | checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/17930#comment:8>

Django

unread,
Nov 15, 2018, 9:44:53 AM11/15/18
to django-...@googlegroups.com
#17930: Error in Queryset with operator | (union queryset) + slice
-------------------------------------+-------------------------------------
Reporter: vini.gracindo@… | Owner: Ian Foote
Type: Bug | Status: closed

Component: Database layer | Version: 1.3
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: queryset union, | Triage Stage: Ready for
slice | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Reply all
Reply to author
Forward
0 new messages