-
-
Notifications
You must be signed in to change notification settings - Fork 89
DESIGN ERROR: Dependency Injection and settings_customize_sources
#506
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
Comments
settings_customize_sources
I've deleted my previous comments as I strive to articulate the problem here. It is likely that a BaseSettings loads from env and CLI and potentially other places to meet the Liskov object substitution principle. There is no new API or convention to call to get a BaseSettings to do its job, and once done, it can substitute for any other pydantic model. However, in so doing, the method |
I should also add that this violation is emergent - the only default source other than init settings are environment variables, and that can be effectively disabled using |
Thanks @danizen for reporting this issue. By default pydantic-settings has BTW, we are open to changes and I think we can change it in V3. Feel free to put an example code here if you have any suggestions. it doesn't need to be a perfect working code. |
Here is what I am concerned about in terms of the principle of least surprise and dependency injection: https://gist.github.com/danizen/61de10c4c601fa36c97a65546b785248 |
As you can see, I found a solution which works for me. I'm fooling around with model_dump and so on to get a true copy going. |
Thanks @danizen for providing the example code. I assume you meant we need an easy way to determine the required setting sources for the settings model when we initialize the settings object. right now, we need to define a fixed set of sources in |
I've done a lot of work to migrate to pydantic settings, but as I get started with unit testing the code, I see the potential for all sorts of side effects when I do things like this:
Essentially, I want to disable the behavior of
settings_customize_sources
most of the time, and only use those sources when resolving. Is there a way to easily override the loading behavior and get the model to behave more like a pydantic BaseModel?The text was updated successfully, but these errors were encountered: