Skip to content

feat: use a configuration without creating an app #741

Closed

Description

@uniqueg

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 bare Flask(__name__) with set_app_config(), and registers the collections with register_mongodb() without indexes.
  • It then runs inside app.app_context(), so that get_config() and get_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() (or foca.config.access.use_config(config)): makes the configuration the one that get_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 documenting register_mongodb(conf, create_indexes=False) as public API), so that get_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 for set_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

  1. added this to the v0.22.0 milestone on Nov 7, 2026
  2. added
    priority: medium
    status: in progress
    type: feature
    workload: hours
    on Nov 7, 2026
  3. removed
    status: in progress
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: featureworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions