Repository navigation
Description
Problem
Found in the pre-release review of FOCA v0.18.0.
foca.plugins.runtime.configure() keeps one GatewayApp for the whole process, and every Foca(...) calls it, also those without gateway=. It refuses other settings only while a host is cached, and create_app() closes the host it creates for its startup check. So, until the first gateway request, any later Foca(...) overwrites the settings, and one without gateway= clears them. After that, create_app() and get_host() raise RuntimeError: No gateway app configured: pass Foca(gateway=...), although gateway= was passed.
Also:
- whether a
GatewayAppwith other settings is refused depends on whether a host exists, i.e., on import order; create_host(),plugin_classes()andget_backend_list()read the configuration of the most recently created FOCA app (get_config()"latest"), which may be another app's (e.g., a Celery worker module's);docs/plugins.mddoes not say that everyFoca(...)in a gateway process must pass the sameGatewayApp.
Scenario (proTES)
pro_tes/celery_worker.py creates a module-level Foca(config_file=...) without gateway=; Connexion imports it (via the TES controllers and track_task_progress) during create_app(). If proTES passes gateway= only in app.py, create_app() fails; if the import happened later, the first gateway request returns a 500.
Proposed fix
- Bind the gateway settings to the configuration of the
Foca(gateway=...)instance that sets them;Foca(...)withoutgateway=leaves them alone. - Refuse other gateway settings in the same process whether or not a host exists (only
foca.plugins.runtime.reset()clears them). - Build hosts and backend lists from the bound configuration, not the latest one.
- Document the rules in
docs/plugins.md. - Regression tests: gateway
Focathen plainFoca; otherGatewayAppsettings; latest configuration of another app.
Activity
fix(plugins): serve only the bound gateway app