-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Pydantic BaseSettings should raise when .env file specified in env_file
does not exist
#4
Comments
env_file
is env_file
does not exist
env_file
does not existenv_file
does not exist
(transferred the issue to pydantic-settings) Settings management will remain, but it'll be managed as a separate repo and pypi package. On that issue, the idea is that you might have and So pydantic-settings shouldn't (by default) raise an error if an env file is missing. Ideas to work around this:
WDYT? |
We're also changing how settings works to use "sources" for all sources in V2, so it should be easy to customise the |
Thanks so much, comments like this mean a lot. |
I think having an easy boolean in I didn't think about the use case you mentioned. In my setup the
I truly mean it! I started being a lover of this library since the dark days of |
Initial Checks
Description
Thank you for adding settings management to Pydantic, it's a pleasure to use a single well-done library to manage both models and settings from .env files and environment variables! 😍
I'm not sure about its future in Pydantic V2 (👀 please don't remove it 🙏 ) since I can't find references in the
main
branch anymore. Still I'd like to mention a small improvement that could be done when reading .env files.Currently, if the
.env
file does not exist it is simply ignored. I don't know if this is done by design but I would actually prefer a strict behaviour that raises an error asap.What happened to me instead is that I provided a wrong path in the
env_file
and pydantic later raised with a ValidationError for missing fields that were specified in the .env file. I still consider this a lucky case because an error was eventually raised. What would have been worse is if my settings had defaults for every field, which would have resulted in no ValidationError being raised at all!Let me know what do you think about it. If you have a strong preference for the current behaviour I guess I could always add some file existence check before parsing my settings. Still, it would be nice to have this done by Pydantic IMO.
Could you also share an update on the planned support for settings in V2? In the online v2 plan there isn't a final answer, but I imagine you have already taken actions on it.
Thank you so much and keep making Pydantic one of the best libraries of the Python ecosystem 🚀
Affected Components
.dict()
and.json()
construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: