Skip to content

Ignore extra configs in .env file

Tan Le requested to merge ignore-extra-configs into main

What does this merge request do and why?

Ignore extra configs in .env file

pydantic-settings-2.2.0 forbids extra configs by default when prefix is used. This causes unexpected errors when there are extra items in their local .env file.

Issue first reported by @lesley-r https://gitlab.slack.com/archives/C051K31F30R/p1708530464757359

Whenever I run poetry run ai_gateway, it says:

pydantic_core._pydantic_core.ValidationError: 2 validation errors for Config
api_external_port
  Extra inputs are not permitted [type=extra_forbidden, input_value='5001', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/extra_forbidden
anthropic_api_key
  Extra inputs are not permitted [type=extra_forbidden, input_value='[REDACTED]', input_type=str]
    For further information visit https://errors.pydantic.dev/2.6/v/extra_forbidden

If I comment out those lines in the .env file, the server can start, but of course I can't make requests due to the lack of an API key.

How to set up and validate locally

  1. Verify the above error by adding a ANTHROPIC_API_KEY=abc in the .env file
  2. Check out to this merge request's branch.
  3. Run poetry run ai_gateway and ensure the error no longer shows.

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Tan Le

Merge request reports