Skip to content

Enforce synchronization between Settings class and .env.example #680

@agennadi

Description

@agennadi

Context

Our FastAPI backend uses a centralized Settings class (in backend/api/config.py) to manage environment variables loaded from the .env file. We also maintain a .env.example file that serves as a reference for required variables - useful for onboarding new developers and CI setup.

Currently, there’s no safeguard ensuring that new variables added to the Settings class are also reflected in .env.example. This often leads to inconsistencies where:

  • .env.example misses required variables;
  • CI/CD fails because expected environment variables are undefined;

We need a mechanism to enforce that every field defined in the Settings class exists in .env.example, even if with a dummy placeholder value.

Definition of Done

  • Implement a validation script (e.g., scripts/check_env_sync.py) that:
    • Parses the Settings class to extract all defined environment variable names.
    • Reads .env.example and compares variable keys.
    • Reports any missing variables.
  • Add this check to CI or the pre-commit hook.

Engineering Details

Settings.model_fields.keys() returns a view object containing the names of all the fields defined on a Pydantic settings model.

Metadata

Metadata

Labels

back endinfrastructureDevOps, deployments, hosting, site reliability, etc. What doesn't fit neatly into FE or BE.

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions