[Django] #34267: Error with Union queryset not being paginable

6 views
Skip to first unread message

Django

unread,
Jan 17, 2023, 11:19:44 AM1/17/23
to django-...@googlegroups.com
#34267: Error with Union queryset not being paginable
-----------------------------------------+------------------------
Reporter: rphlo | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
I tried 4.2a1 today on my project and I noticed pagination was broken on
one view.

After little investigation I manage to reproduce an error:

`Event` is a model with `set` a Foreignkey
{{{
>> events = Event.objects.all()
>> events_without_set = events.filter(set__isnull=True)
>> one_event_of_each_set = (
events.filter(set__isnull=False)
.order_by("set_id")
.distinct("set_id")
)
>> my_list = events_without_set.union(one_event_of_each_set)
>> my_list.count()
212
>> my_list[2]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/venv/lib/python3.11/site-packages/django/db/models/query.py",
line 450, in __getitem__
return qs._result_cache[0]
~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
}}}

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

Django

unread,
Jan 17, 2023, 11:26:07 AM1/17/23
to django-...@googlegroups.com
#34267: Error with Union queryset not being paginable
-------------------------------+--------------------------------------

Reporter: rphlo | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Description changed by rphlo:

Old description:

> I tried 4.2a1 today on my project and I noticed pagination was broken on
> one view.
>
> After little investigation I manage to reproduce an error:
>
> `Event` is a model with `set` a Foreignkey
> {{{
> >> events = Event.objects.all()
> >> events_without_set = events.filter(set__isnull=True)
> >> one_event_of_each_set = (
> events.filter(set__isnull=False)
> .order_by("set_id")
> .distinct("set_id")
> )
> >> my_list = events_without_set.union(one_event_of_each_set)
> >> my_list.count()
> 212
> >> my_list[2]
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "/venv/lib/python3.11/site-packages/django/db/models/query.py",
> line 450, in __getitem__
> return qs._result_cache[0]
> ~~~~~~~~~~~~~~~~^^^
> IndexError: list index out of range
> }}}

New description:

I tried 4.2a1 today on my project and I noticed pagination was broken on
one view.

After little investigation I manage to reproduce an error:

`Event` is a model with `set` a Foreignkey
{{{
>> events = Event.objects.all()
>> events_without_set = events.filter(set__isnull=True)
>> one_event_of_each_set = (
events.filter(set__isnull=False)
.order_by("set_id")
.distinct("set_id")
)
>> my_list = events_without_set.union(one_event_of_each_set)
>> my_list.count()
212
>> my_list[2]
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/venv/lib/python3.11/site-packages/django/db/models/query.py",
line 450, in __getitem__
return qs._result_cache[0]
~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
}}}

With django 4.1.5 `my_list[2]` returns an event.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34267#comment:1>

Django

unread,
Jan 17, 2023, 11:43:57 AM1/17/23
to django-...@googlegroups.com
#34267: Error with Union queryset not being paginable
-------------------------------------+-------------------------------------

Reporter: rphlo | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 4.2
(models, ORM) |

Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by rphlo):

* component: Uncategorized => Database layer (models, ORM)


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

Reply all
Reply to author
Forward
0 new messages