Skip to content

Commit

Permalink
Tie install model scope to request scope
Browse files Browse the repository at this point in the history
This is probably the more general fix for
#18627.
  • Loading branch information
mvdbeek committed Jul 31, 2024
1 parent 42829a5 commit ecd7bbb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/galaxy/web/framework/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,11 @@ def __call__(self, environ, start_response):

try:
self._model.set_request_id(request_id) # Start SQLAlchemy session scope
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
self._install_model.unset_request_id(request_id) # End SQLAlchemy session scope
self.trace(message="Handle request finished")
if self.trace_logger:
self.trace_logger.context_remove("request_id")
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/webapps/base/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def __init__(
# 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):
"""
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy/webapps/galaxy/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit ecd7bbb

Please sign in to comment.