Repository navigation
Description
Problem
Middlewares get the flask.Request of POST /tasks
(AbstractMiddleware.apply_middleware(request) -> request), and
TaskRuns reads flask.request directly (create_task(),
list_tasks()). FOCA 1.0 drops Flask (Connexion 3 AsyncApp), and the
maintainer's hard constraint is that nothing prepared now may block that
migration: task processing and plugin-facing code must get plain data,
with the Flask/Connexion glue confined to the controllers. It also makes
the adoption of FOCA's plugin engine (T1) larger than it needs to be,
because the middleware call is tangled with request handling.
Proposal
- Interface:
AbstractMiddleware.apply_middleware(task: dict) -> dict.
The handler gives each alternative its own deep copy and keeps it only
on success (same semantics as FOCA's engine); alternatives that return
no task (not adict) fail, too. The built-in middlewares are ported. - The controllers (
server.CreateTask,server.ListTasks) are the
only code that reads the request: they pass the task (Connexion's
body) and the request path (collection) toTaskRuns, which has
no Flask import and no longer changes the task of the request (it
works on a copy). - Seam for T1:
TaskRuns._apply_middlewares(task) -> (task, tes_urls)
wraps the handler and thetes_urlsextraction (500via
MiddlewareExceptionif middlewares select no list of URLs). T1
replaces this method withhost.start()/request()/route(). - ast-grep rule
framework-free-tasks(with rule tests): noflask,
werkzeug,connexionorstarletteimports in
pro_tes/ga4gh/tes/task_runs.py,pro_tes/middleware/,
pro_tes/plugins/. - Docs (
docs/middlewares.md): the new interface and copy semantics.
Acceptance criteria
- No Flask, Werkzeug or Connexion import in the task processing and
the middlewares (ast-grep rule, checked to fire on the old code). - Order of the security checks in
create_task()unchanged; the
task of the request is not changed (test); failed alternatives
leave no trace, also those returning no task (tests). - Middlewares that select no
tes_urlslist fail the request
(500), and the task is not kept (tests). - ruff, mypy, ast-grep, semgrep, pytest (100% coverage),
mkdocs build --strictpass locally.
Verification (local)
All checks pass on f4d434e (1042 passed, 80 skipped; 100% coverage).
Not run: smoke test (Docker Compose), MongoDB 7.0 matrix entry.
Release notes (for the proTES release)
Breaking for custom middlewares: implement
apply_middleware(task: dict) -> dict instead of taking and returning a
flask.Request. (T1 replaces middlewares by FOCA plugins in the same or
the next release; if both land in one release, mention only T1.)
Dependencies
- Blocked by fix: undo changes of failed middlewares #313 (stacked) and fix: keep the backend order in middlewares #314 (merged in). Merge
after both; then update the branch fromdev. - Makes T1 (FOCA plugin adoption, to be filed) smaller.
Open questions
- None.
Activity
fix: reject empty backend lists before storing