[GH-ISSUE #77] Error when using both page and limit #53

Closed
opened 2026-02-26 01:33:00 +03:00 by kerem · 2 comments
Owner

Originally created by @berislavlopac on GitHub (Dec 4, 2018).
Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/77

When I make a request containing both page and limit (e.g. /foo/bar/?limit=50&page=1), I'm getting the following error:

Traceback (most recent call last):
  File "/var/task/flask/app.py", line 2292, in wsgi_app
  response = self.full_dispatch_request()
  File "/var/task/flask/app.py", line 1815, in full_dispatch_request
  rv = self.handle_user_exception(e)
  File "/var/task/flask/app.py", line 1718, in handle_user_exception
  reraise(exc_type, exc_value, tb)
  File "/var/task/flask/_compat.py", line 35, in reraise
  raise value
  File "/var/task/flask/app.py", line 1813, in full_dispatch_request
  rv = self.dispatch_request()
  File "/var/task/flask/app.py", line 1799, in dispatch_request
  return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/task/flask/views.py", line 88, in view
  return self.dispatch_request(*args, **kwargs)
  File "/var/task/flask/views.py", line 158, in dispatch_request
  return meth(*args, **kwargs)
  File "/var/task/sandman2/decorators.py", line 21, in wrapped
  response = func(*args, **kwargs)
  File "/var/task/sandman2/service.py", line 102, in get
  self.__json_collection_name__: self._all_resources()
  File "/var/task/sandman2/service.py", line 226, in _all_resources
  resources = queryset.paginate(int(request.args['page'])).items
  File "/var/task/flask_sqlalchemy/__init__.py", line 501, in paginate
  total = self.order_by(None).count()
  File "<string>", line 2, in order_by
  File "/var/task/sqlalchemy/orm/base.py", line 200, in generate
  assertion(self, fn.__name__)
  File "/var/task/sqlalchemy/orm/query.py", line 401, in _no_limit_offset
  % (meth, meth)
sqlalchemy.exc.InvalidRequestError: Query.order_by() being called on a Query which already has LIMIT or OFFSET applied. To modify the row-limited results of a  Query, call from_self() first.  Otherwise, call order_by() before limit() or offset() are applied.

It's working fine when either of the arguments stands alone.

Originally created by @berislavlopac on GitHub (Dec 4, 2018). Original GitHub issue: https://github.com/jeffknupp/sandman2/issues/77 When I make a request containing both `page` and `limit` (e.g. `/foo/bar/?limit=50&page=1`), I'm getting the following error: ``` Traceback (most recent call last): File "/var/task/flask/app.py", line 2292, in wsgi_app response = self.full_dispatch_request() File "/var/task/flask/app.py", line 1815, in full_dispatch_request rv = self.handle_user_exception(e) File "/var/task/flask/app.py", line 1718, in handle_user_exception reraise(exc_type, exc_value, tb) File "/var/task/flask/_compat.py", line 35, in reraise raise value File "/var/task/flask/app.py", line 1813, in full_dispatch_request rv = self.dispatch_request() File "/var/task/flask/app.py", line 1799, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/var/task/flask/views.py", line 88, in view return self.dispatch_request(*args, **kwargs) File "/var/task/flask/views.py", line 158, in dispatch_request return meth(*args, **kwargs) File "/var/task/sandman2/decorators.py", line 21, in wrapped response = func(*args, **kwargs) File "/var/task/sandman2/service.py", line 102, in get self.__json_collection_name__: self._all_resources() File "/var/task/sandman2/service.py", line 226, in _all_resources resources = queryset.paginate(int(request.args['page'])).items File "/var/task/flask_sqlalchemy/__init__.py", line 501, in paginate total = self.order_by(None).count() File "<string>", line 2, in order_by File "/var/task/sqlalchemy/orm/base.py", line 200, in generate assertion(self, fn.__name__) File "/var/task/sqlalchemy/orm/query.py", line 401, in _no_limit_offset % (meth, meth) sqlalchemy.exc.InvalidRequestError: Query.order_by() being called on a Query which already has LIMIT or OFFSET applied. To modify the row-limited results of a Query, call from_self() first. Otherwise, call order_by() before limit() or offset() are applied. ``` It's working fine when either of the arguments stands alone.
kerem closed this issue 2026-02-26 01:33:00 +03:00
Author
Owner

@jeffknupp commented on GitHub (Dec 15, 2018):

Can you check which version of sandman2 you're running? I just tried to reproduce this unsuccessfully and I think this was fixed by a PR merged in the last few weeks.

<!-- gh-comment-id:447604689 --> @jeffknupp commented on GitHub (Dec 15, 2018): Can you check which version of `sandman2` you're running? I just tried to reproduce this unsuccessfully and I think this was fixed by a PR merged in the last few weeks.
Author
Owner

@berislavlopac commented on GitHub (Dec 16, 2018):

Hah! Based on the dates, it was literally merged the same day I have set that instance up! 😆

Thank you for the amazing work!

<!-- gh-comment-id:447680982 --> @berislavlopac commented on GitHub (Dec 16, 2018): Hah! Based on the dates, it was literally merged the same day I have set that instance up! :laughing: Thank you for the amazing work!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/sandman2-jeffknupp#53
No description provided.