Fix SQL error with pagination around Repositories

Fixes #1591
This commit is contained in:
Joseph Schorr 2016-06-30 17:31:35 -04:00
parent 36fa93a0fb
commit 1eec6f53b2
4 changed files with 27 additions and 14 deletions

View file

@ -1,4 +1,4 @@
def paginate(query, model, descending=False, page_token=None, limit=50):
def paginate(query, model, descending=False, page_token=None, limit=50, id_field='id'):
""" Paginates the given query using an ID range, starting at the optional page_token.
Returns a *list* of matching results along with an unencrypted page_token for the
next page, if any. If descending is set to True, orders by the ID descending rather
@ -7,9 +7,9 @@ def paginate(query, model, descending=False, page_token=None, limit=50):
query = query.limit(limit + 1)
if descending:
query = query.order_by(model.id.desc())
query = query.order_by(getattr(model, id_field).desc())
else:
query = query.order_by(model.id)
query = query.order_by(getattr(model, id_field))
if page_token is not None:
start_id = page_token.get('start_id')