Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a variable has the same two prefixes, the additional environment variable can't allow or forbid. #384

Closed
gbaian10 opened this issue Sep 9, 2024 · 2 comments · Fixed by #386
Assignees
Labels
bug Something isn't working

Comments

@gbaian10
Copy link

gbaian10 commented Sep 9, 2024

from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env", extra="allow")

    POSTGRES_USER: str


print(Settings())

.env

POSTGRES_USER=postgres
POSTGRES_USER_2=postgres2  # can't allow or forbid
POSTGRES_NAME=name  # can allow or forbid

output miss POSTGRES_USER_2

POSTGRES_USER='postgres' postgres_name='name'

Replace allow with forbid.

pydantic_core._pydantic_core.ValidationError: 1 validation error for Settings
postgres_name
  Extra inputs are not permitted [type=extra_forbidden, input_value='name', input_type=str]
    For further information visit https://errors.pydantic.dev/2.9/v/extra_forbidden

Missing extra input for POSTGRES_USER_2 raise.


pydantic==2.9.1
pydantic-settings==2.4.0

@hramezani
Copy link
Member

Thanks @gbaian10 for reporting this issue.
I created #386 to fix the problem.

Could you please confirm?

@hramezani hramezani assigned hramezani and unassigned dmontagu Sep 10, 2024
@hramezani hramezani added bug Something isn't working and removed unconfirmed labels Sep 10, 2024
@gbaian10
Copy link
Author

Thanks @gbaian10 for reporting this issue. I created #386 to fix the problem.

Could you please confirm?

@hramezani

The current test output is as expected! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants