You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I originally posted this as a comment in #2106 (comment), but it probably deserves its own question.
I read the issue #2106 and the PR #2107 that got merged in Pydantic 1.8 with great interest, as I had exactly the same problem (thank you so much for this work 🎉).
I wanted to ask the same question almost a year ago, when I started working on a POC to extend Pydantic settings with Hashicorp Vault (see https://github.com/nymous/pydantic-vault). I ended up overloading the _build_values method, thinking it would be relatively safe as this was the only method I changed, but it broke with Pydantic 1.7 and the support for Docker secrets.
I have found this other project that went the same route https://github.com/kewtree1408/pydantic-azure-secrets, I should point them to here and tell them about the new way ^^
I still have a few questions: now that we can extend how Pydantic loads variables, what would be the best way to write a reusable provider (to be published on PyPI)? Should I just export a vault_config_settings_source() function that users can insert in their own BaseSettings class? Should I also provide a VaultBaseSettings class that they can inherit from, and that already has this custom source configured? For the properties, should I keep using the kwargs from the Field() function as I have written in my readme, or subclass it as VaultField?
Finally, how safe will this source customization be regarding to Pydantic updates? From the example in the PR https://github.com/samuelcolvin/pydantic/pull/2107/files#diff-401519a4e7dfa8678034b93ab8841dc323994f8e4457151118a02814d53aaaaa I can see that the customise_sources method takes init_settings, env_settings and file_secret_settings arguments, what will happen if Pydantic ever supports another way of loading values?
Thank you for reading, and thanks to everyone who makes Pydantic awesome ❤️
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi!
I originally posted this as a comment in #2106 (comment), but it probably deserves its own question.
I read the issue #2106 and the PR #2107 that got merged in Pydantic 1.8 with great interest, as I had exactly the same problem (thank you so much for this work 🎉).
I wanted to ask the same question almost a year ago, when I started working on a POC to extend Pydantic settings with Hashicorp Vault (see https://github.com/nymous/pydantic-vault). I ended up overloading the
_build_values
method, thinking it would be relatively safe as this was the only method I changed, but it broke with Pydantic 1.7 and the support for Docker secrets.I have found this other project that went the same route https://github.com/kewtree1408/pydantic-azure-secrets, I should point them to here and tell them about the new way ^^
I still have a few questions: now that we can extend how Pydantic loads variables, what would be the best way to write a reusable provider (to be published on PyPI)? Should I just export a
vault_config_settings_source()
function that users can insert in their ownBaseSettings
class? Should I also provide aVaultBaseSettings
class that they can inherit from, and that already has this custom source configured? For the properties, should I keep using thekwargs
from theField()
function as I have written in my readme, or subclass it asVaultField
?Finally, how safe will this source customization be regarding to Pydantic updates? From the example in the PR https://github.com/samuelcolvin/pydantic/pull/2107/files#diff-401519a4e7dfa8678034b93ab8841dc323994f8e4457151118a02814d53aaaaa I can see that the
customise_sources
method takesinit_settings
,env_settings
andfile_secret_settings
arguments, what will happen if Pydantic ever supports another way of loading values?Thank you for reading, and thanks to everyone who makes Pydantic awesome ❤️
Beta Was this translation helpful? Give feedback.
All reactions