Opened 22 months ago

Last modified 22 months ago

#34267 closed Bug

Error with Union queryset not being paginable — at Initial Version

Reported by: Raphaël Stefanini Owned by: nobody
Component: Database layer (models, ORM) Version: 4.2
Severity: Release blocker Keywords:
Cc: Simon Charette 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

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

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top