{"record":{"id":"8bdd3f32cfd7dc9c","repo":"ruvnet/RuView","slug":"environment-must-be-one-of-allowed-environments","errorCode":null,"errorMessage":"Environment must be one of: {allowed_environments}","messagePattern":"Environment must be one of: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archive/v1/src/config/settings.py","lineNumber":182,"sourceCode":"        env_file=\".env\",\n        env_file_encoding=\"utf-8\",\n        case_sensitive=False,\n        # Tolerate `.env` keys that this Settings model doesn't declare\n        # (e.g., NPM_TOKEN, DOCKER_HUB_TOKEN, PYPI_TOKEN used by other\n        # tooling). Without `extra=\"ignore\"` pydantic-settings 2.x\n        # raises `ValidationError: Extra inputs are not permitted` and\n        # leaks the offending values into the error message — a real\n        # security concern for secret tokens. See verify.py / `./verify`.\n        extra=\"ignore\",\n    )\n    \n    @field_validator(\"environment\")\n    @classmethod\n    def validate_environment(cls, v):\n        \"\"\"Validate environment setting.\"\"\"\n        allowed_environments = [\"development\", \"staging\", \"production\"]\n        if v not in allowed_environments:\n            raise ValueError(f\"Environment must be one of: {allowed_environments}\")\n        return v\n    \n    @field_validator(\"log_level\")\n    @classmethod\n    def validate_log_level(cls, v):\n        \"\"\"Validate log level setting.\"\"\"\n        allowed_levels = [\"DEBUG\", \"INFO\", \"WARNING\", \"ERROR\", \"CRITICAL\"]\n        if v.upper() not in allowed_levels:\n            raise ValueError(f\"Log level must be one of: {allowed_levels}\")\n        return v.upper()\n    \n    @field_validator(\"pose_confidence_threshold\")\n    @classmethod\n    def validate_confidence_threshold(cls, v):\n        \"\"\"Validate confidence threshold.\"\"\"\n        if not 0.0 <= v <= 1.0:\n            raise ValueError(\"Confidence threshold must be between 0.0 and 1.0\")\n        return v","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/ruvnet/RuView/blob/4685618388a5e49fad5b3005806f3bdd6a7c25c3/archive/v1/src/config/settings.py#L164-L200","documentation":"Pydantic v2 @field_validator on Settings.environment in archive/v1/src/config/settings.py. It enforces exact membership in ['development', 'staging', 'production'] — a case-sensitive check with no .lower() normalization, so 'Production', 'prod', 'dev', and 'test' are all rejected. Because this is a pydantic-settings class, the value typically arrives from the ENVIRONMENT env var, and an invalid value fails at Settings() construction, usually at application startup.","triggerScenarios":"ENVIRONMENT=dev, ENVIRONMENT=prod, or ENVIRONMENT=test (common shorthand); ENVIRONMENT=Production (capitalized — rejected by the case-sensitive comparison); trailing whitespace like 'production ' from .env files; CI setting ENVIRONMENT=ci.","commonSituations":"Copying shorthand values from docker-compose or Makefiles of other projects; capitalized values in .env files; whitespace introduced by 'KEY=value # comment' parsing; new environments (ci, local, qa) not being added to the allow-list.","solutions":["Set ENVIRONMENT to the exact lowercase full word: development, staging, or production","Strip whitespace and avoid inline comments on the ENVIRONMENT line in .env files","Normalize in a wrapper if you must accept shorthand (env = {'dev': 'development', 'prod': 'production'}.get(raw, raw))","If you genuinely need a new environment like 'ci', add it to allowed_environments in the validator"],"exampleFix":"# before\nENVIRONMENT=prod\n\n# after\nENVIRONMENT=production","handlingStrategy":"validation","validationCode":"ALLOWED = {\"development\", \"staging\", \"production\"}\nraw = os.environ.get(\"ENVIRONMENT\", \"development\").strip().lower()\nenvironment = {\"dev\": \"development\", \"prod\": \"production\", \"staging\": \"staging\"}.get(raw, raw)\nassert environment in ALLOWED, f\"ENVIRONMENT must be one of {sorted(ALLOWED)}, got {raw!r}\"","typeGuard":"def is_valid_environment(v: str) -> bool:\n    return v in {\"development\", \"staging\", \"production\"}","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    settings = Settings()\nexcept ValidationError as e:\n    if any(err[\"loc\"][-1] == \"environment\" for err in e.errors()):\n        raise SystemExit(\"ENVIRONMENT must be exactly development|staging|production (lowercase, no shorthand)\") from e\n    raise","preventionTips":["Use exact lowercase full words in ENVIRONMENT; the validator is case-sensitive","Normalize shorthand (dev/prod) and whitespace in deployment scripts before the app reads them","Add new environment names to the validator allow-list deliberately, with a PR"],"tags":["pydantic","settings","environment-variables","validation","config","python"],"backgroundTag":null,"analyzedSha":"4685618388a5e49fad5b3005806f3bdd6a7c25c3","analyzedAt":"2026-08-16T06:09:40.886Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}