Repository navigation
Description
Problem
set_app_config() is deprecated in 0.22.0 and removed in the ASGI release. Apps that FOCA creates don't need it. Scripts and tools that want FOCA's configuration and databases without creating the app have no Flask-free replacement, as "Preparing for the ASGI release" says ("keep the call (it warns) until the ASGI release").
Example: cloud-registry's cloud_registry/namespace_subjects.py --dry-run (_read_only_app()):
- It parses the configuration with
create_foca().conf, attaches it to a bareFlask(__name__)withset_app_config(), and registers the collections withregister_mongodb()without indexes. - It then runs inside
app.app_context(), so thatget_config()andget_collection()see that configuration. - It avoids
create_app()because creating the app writes to the database: FOCA's indexes, the policy sync of access control and the app's own startup tasks. A dry run with a newer image must not change a database that older pods still use.
Today, the only way for a script to make a configuration current for get_config() / get_collection() is a Flask app: set_app_config() (deprecated) or create_app() (writes). foca.no_startup_writes() / Foca.disable_startup_writes() turn off FOCA's own writes, but still create the app (the Connexion/Flask app, specifications, access control) and run the app's own startup code.
Proposal
A public, framework-neutral way to use a FOCA configuration without an app, e.g.:
Foca.use_config()(orfoca.config.access.use_config(config)): makes the configuration the one thatget_config()returns outside app contexts (as the configuration of the most recently created app is today), without creating an app.- Optionally,
Foca.register_db(create_indexes=False)(or documentingregister_mongodb(conf, create_indexes=False)as public API), so thatget_collection()works for the configured collections.
Scripts then need neither Flask nor an app context:
foca = create_foca()
foca.disable_startup_writes()
foca.use_config()
foca.register_db() # collections without indexes
namespace_subjects(namespace, dry_run=True)Scope
- API, tests (also: works without a Flask app context; the most recent of
use_config()and app creation wins, or a documented rule), and docs: "Preparing for the ASGI release" (replace "no Flask-free replacement in 0.22"), the migration guide's table forset_app_config(), and the API reference. - Not in scope: the app-specific startup tasks of apps such as cloud-registry (they keep their own switch).
Related: #188. Ships in 0.22.0, so that apps can move away from set_app_config() before the ASGI release, as the migration guide promises replacements in 0.22 where possible.
Activity