Search code examples
djangopython-3.xdjango-tables2

How to prevent a row count from being sent to the db when paginator is disabled


I'm using Django 1.11, Django-tables2 1.19.0 with MS SQL via django-pyodbc-azure 1.11.0.0.

I'm showing a table for a model that is for a rather slow view which unfortunately must run sub-queries for every row. I can't change the view, and so I've disabled the paginator for tables2 and done a slice to limit the number of rows the view subqueries will run on:

def my_view(request):
    queryset = my_model.objects.all()
    table = my_table(queryset.all()[:25])  # <- only get top 25
    RequestConfig(request, paginate=False).configure(table)
    return render(request, 'my_template.html', {'table': table})

I also disabled ordering for the columns.

That works, however, when using django-admin-toolbar, I can see that a "...COUNT_BIG(*) FROM (SELECT TOP 25..." is nevertheless being sent to the server.

I want to prevent that COUNT_BIG if possible for performance reasons, but my various misguided attempts over the last few days have all met with horrible failure.

I'd really appreciate any help with this one. Thanks.


Solution

  • This was a bug in django-tables2 and should be fixed with commit 942f05e.

    The fix is released as version 1.21.1.