#34067: django.core.Paginator wrong query slicing
-------------------------------------+-------------------------------------
     Reporter:  Hristo Trendafilov   |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Core (Other)         |                  Version:  3.2
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
  Paginator,slice,queryset           |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * resolution:   => needsinfo


Comment:

 > It is Django fault for those reasons:
 >
 > * `order_by` might be complicated but is supported by the framework
 > * Chained `order_by` is also supported

 Yes, but you should be aware what you are using in the `ORDER BY` clause
 and that some fields may cause issues, e.g. multi-valued fields (see
 [https://docs.djangoproject.com/en/stable/ref/models/querysets/#order-by
 notes in docs]). Django cannot decide for you.

 > * queryset slicing is a feature of Django queryset API.
 > * queryset slicing should act like list and string slicing and namely to
 provide you with results `[ from : to ]` indexes provided and not to
 change or lose data in between. Or in other words - what is passed in the
 `Paginator.object_list` should be just sliced `[ from : to ]`. `Paginator`
 should never care for the queryset, what is the ordering of the queryset,
 what is excluded and so on - it should just work with it.

 This would require fetching all results and slicing on the Python side not
 in the database which is very ineffective and would cause many performance
 issues.

 > * changing `paginate_by` to `10` or greater fixes the problem.
 `paginate_by` is a standard and documented Django ListView setting.
 > * changing `order_by` to some other `order_by` also fixes the problem.
 `order_by` should work the same or if any limitations those should be well
 documented

 Limitations are mostly documented, but we cannot document all caveats.

 > P.S. That is also happening in Django 2.2

 Django 2.2 is not supported anymore, and Django 3.2 is in extended support
 so it receives only security patches.


 I understand that you spend a lot of time trying to debug your issue, but
 we don't have your app, your data, and your database, so we're unable to
 help. Also, Trac is not a support channel.

 I'd like to highly recommend using one of
 [https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
 support channel] where folks will help you. If you'll still be convinced
 that Django is at fault, then please attach a sample minimal project that
 reproduces the issue.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701839cc81ae9-23d224f1-db83-438d-a48a-822805a104ca-000000%40eu-central-1.amazonses.com.

Reply via email to