Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative offset and limit emitted somewhere in the library interface #18043

Open
mvdbeek opened this issue Apr 23, 2024 · 0 comments
Open

Negative offset and limit emitted somewhere in the library interface #18043

mvdbeek opened this issue Apr 23, 2024 · 0 comments

Comments

@mvdbeek
Copy link
Member

mvdbeek commented Apr 23, 2024

These are eventually translated to SQL, and that fails.

From https://sentry.galaxyproject.org/share/issue/3e1221e53d2840b788cfef08a4a8770e/:

InvalidRowCountInResultOffsetClause: OFFSET must not be negative

  File "sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
DataError: (psycopg2.errors.InvalidRowCountInResultOffsetClause) OFFSET must not be negative

[SQL: SELECT library_folder.id, library_folder.parent_id, library_folder.create_time, library_folder.update_time, library_folder.name, library_folder.description, library_folder.order_id, library_folder.item_count, library_folder.deleted, library_folder.purged, library_folder.genome_build 
FROM library_folder 
WHERE library_folder.parent_id = %(parent_id_1)s AND library_folder.deleted = false GROUP BY library_folder.id ORDER BY library_folder.name
 LIMIT ALL OFFSET %(param_1)s]
[parameters: {'parent_id_1': 1406, 'param_1': -4}]
(Background on this error at: https://sqlalche.me/e/14/9h9h)
  File "starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "starlette_context/middleware/raw_middleware.py", line 92, in __call__
    await self.app(scope, receive, send_wrapper)
  File "starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
  File "contextlib.py", line 155, in __exit__
    self.gen.throw(typ, value, traceback)
  File "starlette/_utils.py", line 93, in collapse_excgroups
    raise exc
  File "starlette/middleware/base.py", line 191, in __call__
    response = await self.dispatch_func(request, call_next)
  File "galaxy/webapps/galaxy/fast_app.py", line 108, in add_x_frame_options
    response = await call_next(request)
  File "starlette/middleware/base.py", line 165, in call_next
    raise app_exc
  File "starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
  File "starlette/middleware/exceptions.py", line 62, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "starlette/routing.py", line 758, in __call__
    await self.middleware_stack(scope, receive, send)
  File "starlette/routing.py", line 778, in app
    await route.handle(scope, receive, send)
  File "starlette/routing.py", line 299, in handle
    await self.app(scope, receive, send)
  File "starlette/routing.py", line 79, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "starlette/routing.py", line 74, in app
    response = await func(request)
  File "fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
  File "fastapi/routing.py", line 193, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "starlette/concurrency.py", line 42, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
  File "anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
  File "anyio/_backends/_asyncio.py", line 2144, in run_sync_in_worker_thread
    return await future
  File "anyio/_backends/_asyncio.py", line 851, in run
    result = context.run(func, *args)
  File "galaxy/webapps/galaxy/api/folder_contents.py", line 117, in index
    return self.service.index(trans, folder_id, payload)
  File "galaxy/webapps/galaxy/services/library_folder_contents.py", line 76, in index
    contents, total_rows = self.folder_manager.get_contents(trans, folder, payload)
  File "galaxy/managers/folders.py", line 418, in get_contents
    folders = sa_session.scalars(sub_folders_stmt).all()
  File "<string>", line 2, in scalars
  File "sqlalchemy/orm/session.py", line 1778, in scalars
    return self.execute(
  File "sqlalchemy/orm/session.py", line 1717, in execute
    result = conn._execute_20(statement, params or {}, execution_options)
  File "sqlalchemy/engine/base.py", line 1710, in _execute_20
    return meth(self, args_10style, kwargs_10style, execution_options)
  File "sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
  File "sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
    ret = self._execute_context(
  File "sqlalchemy/engine/base.py", line 1953, in _execute_context
    self._handle_dbapi_exception(
  File "sqlalchemy/engine/base.py", line 2134, in _handle_dbapi_exception
    util.raise_(
  File "sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "sqlalchemy/engine/base.py", line 1910, in _execute_context
    self.dialect.do_execute(
  File "sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)

I can limit the API easily, but this also requires a fix in the library (or folder) interface.

mvdbeek added a commit to mvdbeek/galaxy that referenced this issue Apr 23, 2024
And set minimum limit consistently to 1 ... 0 doesn't seem to have much
utility but would also be an option.

Fixes part of galaxyproject#18043.
@martenson martenson self-assigned this Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To Do, Assigned
Development

No branches or pull requests

2 participants