Skip to content

no-defaulted-environment-setting

A settings field that names the deployment environment must not declare a default.

Why

A defaulted environment setting lets a deployment that forgot the variable start as the default environment, so it quietly behaves like local or development code and can share state with another stack.

Fix

Declare the field without a default, for example environment: Environment = Field(alias="ENVIRONMENT"), so a missing value fails at startup.

Examples

Before — flagged A defaulted environment pretends to be local
service/settings.py
from pydantic import Field
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
environment: str = Field(default="local", alias="ENVIRONMENT")
After — preferred A required environment fails at startup when missing
service/settings.py
from pydantic import Field
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
environment: str = Field(alias="ENVIRONMENT")