Unverified Commit d83b56b4 authored by mvdbeek's avatar mvdbeek
Browse files

Tie install model scope to request scope

This is probably the more general fix for
https://github.com/galaxyproject/galaxy/issues/18627.
parent 42829a5c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -171,9 +171,13 @@ class WebApplication:

        try:
            self._model.set_request_id(request_id)  # Start SQLAlchemy session scope
            if self._install_model:
                self._install_model.set_request_id(request_id)
            return self.handle_request(request_id, path_info, environ, start_response)
        finally:
            self._model.unset_request_id(request_id)  # End SQLAlchemy session scope
            if self._install_model:
                self._install_model.unset_request_id(request_id)
            self.trace(message="Handle request finished")
            if self.trace_logger:
                self.trace_logger.context_remove("request_id")
+1 −0
Original line number Diff line number Diff line
@@ -121,6 +121,7 @@ class WebApplication(base.WebApplication):
        # We need this to set the REQUEST_ID contextvar in model.base *BEFORE* a GalaxyWebTransaction is created.
        # This will ensure a SQLAlchemy session is request-scoped for legacy (non-fastapi) endpoints.
        self._model = galaxy_app.model
        self._install_model = getattr(galaxy_app, "install_model", None)

    def build_apispec(self):
        """
+2 −0
Original line number Diff line number Diff line
@@ -98,10 +98,12 @@ async def get_app_with_request_session() -> AsyncGenerator[StructuredApp, None]:
    app = get_app()
    request_id = request_context.data["X-Request-ID"]
    app.model.set_request_id(request_id)
    app.install_model.set_request_id(request_id)
    try:
        yield app
    finally:
        app.model.unset_request_id(request_id)
        app.install_model.unset_request_id(request_id)


DependsOnApp = cast(StructuredApp, Depends(get_app_with_request_session))
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ log = logging.getLogger(__name__)
class GalaxyWebApplication(galaxy.webapps.base.webapp.WebApplication):
    injection_aware = True


def app_factory(*args, **kwargs):
    """
    Return a wsgi application serving the root object