If max_returned_rows==page_size, increment max_returned_rows

Fixes #230, where if the two were equal pagination didn't work correctly.
This commit is contained in:
Simon Willison 2018-04-25 21:04:12 -07:00
commit 4504d5160b
No known key found for this signature in database
GPG key ID: 17E2DEA2588B7F52
3 changed files with 28 additions and 6 deletions

View file

@ -176,10 +176,13 @@ class BaseView(RenderMixin):
try:
cursor = conn.cursor()
cursor.execute(sql, params or {})
if self.max_returned_rows and truncate:
rows = cursor.fetchmany(self.max_returned_rows + 1)
truncated = len(rows) > self.max_returned_rows
rows = rows[:self.max_returned_rows]
max_returned_rows = self.max_returned_rows
if max_returned_rows == self.page_size:
max_returned_rows += 1
if max_returned_rows and truncate:
rows = cursor.fetchmany(max_returned_rows + 1)
truncated = len(rows) > max_returned_rows
rows = rows[:max_returned_rows]
else:
rows = cursor.fetchall()
truncated = False