django-autocomplete-light icon indicating copy to clipboard operation
django-autocomplete-light copied to clipboard

UnorderedObjectListWarning

Open tualatrix opened this issue 7 years ago • 3 comments

When using under Python 3.6.1 + Django 1.11.1, there's an warning when hitting the xxxx-autocomplete view:

lib/python3.6/site-packages/django/core/paginator.py:112: UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <QuerySet []> UnorderedObjectListWarning

tualatrix avatar May 10 '17 04:05 tualatrix

Can you paste the whole traceback please ?

Or better, propose a patch <3

jpic avatar May 10 '17 12:05 jpic

I'm having the same issue here.

After of bit of searching it turns out it comes from Paginator which complains because of this remark in Django's documentation.

The fix would be to set the ordering attribute in the autocomplete view. So the question is :

  • should dal's clients systematically set an ordering of their choice? In this case, maybe it would be worth mentioning it the docs, in particular in the tutorial.
  • should dal choose a default ordering to prevent the issue? For instance ordering = ("id", )

Hope I didn't misunderstand the problem.

I'd be happy to propose a patch if you opt for the second option :)

Kerl13 avatar Oct 08 '19 21:10 Kerl13

Well, in general you should have a default ordering in YourModel.meta.ordering, not sure if that will fix the issue, but in this case dal should not override the ordering with its own default.

Then, I suppose the ordering that would make sense would be based on the field that the user is searching into.

Feel free to open a PR if you feel strongly about it.

Best

jpic avatar Oct 09 '19 09:10 jpic