Can't iterate NoneType using offset and count on search method


I found this case where I’m building a web application and I write the search method params on the application and then parse them on the server and use all of them in a query like

sales =, offset=offset, order=order, limit=limit, count=count)

I’m querying the route that uses this method from a page that requires pagination so I send a first query that returns the count of records of such query, then the same query without the count…

The problem comes when I navigate to the second page where my offset is already calculated and I queried it on the count query, resulting in this:

SELECT COUNT(*) FROM sale_sale WHERE state = 'quotation' AND company = '1' OFFSET 21;
(0 rows)
Traceback (most recent call last):
  File "/home/hodei/dev/ingsys/client/.venv/lib/python3.10/site-packages/trytond/protocols/", line 237, in wrapper
    response = func(request, *args, **kwargs)
  File "/home/hodei/tryton_app/", line 37, in wrapper
    return func(*args, application, **kwargs)
  File "/home/hodei/tryton_app/", line 107, in sales
    sales =, offset=offset, order=order,
  File "/home/hodei/dev/ingsys/client/.venv/lib/python3.10/site-packages/trytond/model/", line 1322, in search
    return cursor.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable

Without the offset this query returns the correct value

SELECT COUNT(*) FROM sale_sale WHERE state = 'quotation' AND company = '1';
(1 row)

This is an easy fix for me handling the query either on the client or the server but I wonder if this could be considered as a bug, a feature or just a bad use.

Indeed offset does not have sense for a SELECT COUNT(*).
I guess we could improve the behavior in Issue 10967: Add limit to search count - Tryton issue tracker by supporting offset using a subquery.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.