-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Environment variable parsing exception #132
Comments
Yes, because
With this change, it is not a complex field anymore. I think it's not a bug. you can fix it by changing your env to a string. import os
from pydantic_settings import BaseSettings
os.environ['AUTH_KEY'] = '"123456"' # json.loads() will convert it to str
class Settings(BaseSettings):
auth_key: str | None = None
settings = Settings()
print(settings.auth_key) |
I don't think this is a friendly solution, a friendly solution should be to split types such as When I use ".env" file to parse, it will appear weird, for example:
|
You can use the same syntax in
BTW, we are open to accept a PR to change it |
Okay, thank you. I'll try it out. |
Description
When I set the variable type to
str | None
, it usesjson.loads()
to parse the environment variable, so the variable type will change fromstr
toint
type, and this exception is thrown.Although setting to
str
type can avoid the problem, I think this is a bug that can be fixed.Thx. ^_^
Example code
Exception
Version
Selected Assignee: @dmontagu
The text was updated successfully, but these errors were encountered: