ERROR : Exception Value: object of type 'RawStoredProcedureQuerySet' has no len()

Issue #46 wontfix
Anonymous created an issue
def pedidos_view(request,pagina):

    lista_pedidos = VcaOrpe.objects.raw_callproc('[dbo].[WEB_ListadoPedido]',['admin','E'])    
    paginator = Paginator(lista_pedidos,1) # Cuantos productos quieres por pagina? = 3    
    try:
        page = int(pagina)
    except:
        page = 1

    try:
        pedidos = paginator.page(page) #error
    except (EmptyPage,InvalidPage):
        pedidos = paginator.page(paginator.num_pages)        
    ctx = {'pedidos':lista_pedidos}
    return render_to_response('bmpedido/pedidos.html',ctx,context_instance=RequestContext(request))

error

TypeError at /pedidos/page/1/
object of type 'RawStoredProcedureQuerySet' has no len()
Request Method: GET
Request URL:    http://localhost/pedidos/page/1/
Django Version: 1.5.1
Exception Type: TypeError
Exception Value:    
object of type 'RawStoredProcedureQuerySet' has no len()
Exception Location: C:\Python27\lib\site-packages\django\core\paginator.py in _get_count, line 56
Python Executable:  C:\server\bin\httpd.exe
Python Version: 2.7.6
Python Path:    
['c:\\server\\wsgi_app\\portal',
 'C:\\Python27\\lib\\site-packages\\setuptools-2.0-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\django_auth_ldap-1.1.7-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\Lib',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\Lib\\lib-tk',
 'C:\\server',
 'C:\\server\\bin',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\win32',
 'C:\\Python27\\lib\\site-packages\\win32\\lib',
 'C:\\Python27\\lib\\site-packages\\Pythonwin']
Server time:    Fri, 20 Dec 2013 13:56:42 -0500

Comments (3)

  1. Michael Manfre repo owner

    Using RawStoredProcedureQuerySet directly with Paginator doesn't make sense me. At best, it could be changed to behave like a regular list by pulling down the entire resultset, but I don't want to make that an implicit behavior because it defeats any of the potential speed gains of using stored procedures.

    To make your code work with the least amount of effort, evaluate the query to a list before passing it to Paginator.

    Ideally, you would do the paging in the stored procedure, but that will not work with Paginator.

  2. Log in to comment