Opened 12 years ago

Last modified 5 years ago

#17930 closed Bug

Error in Queryset with operator | (union queryset) + slice — at Version 1

Reported by: vini.gracindo@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.3
Severity: Normal Keywords: queryset union, slice
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Łukasz Rekucki)

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.

Change History (1)

comment:1 by Łukasz Rekucki, 12 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top