-
-
Notifications
You must be signed in to change notification settings - Fork 337
-
Hi,
First of all, thanks for creating this great project. I'm using environment variable interpolation with a yaml config file. But when a environment variable is not defined and I try to access it, configuration variable is the literal value in yaml config file.
For example:
When DATABASE_URL
environment variable is defined, my provided config is postgresql://postgres:password@localhost:5432/postgres
But when this variable is not defined, provided config is ${DATABASE_URL}
So is there a way to make these interpolations required? I want to throw some kind of an error if environment variable is not set.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 6 replies
-
Hi @hakanutku ,
So is there a way to make these interpolations required?
No, there is no way to make it right now.
I think this is a reasonable problem. Thanks for bringing this up. I'll think how I can address this.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @rmk135,
Thanks again for the response. This api solves my problem. But I think when envs_required
parameter is set to False
, from_*
methods should load env interpolations as None
and not the literal value if the environment variable is not set. I don't think this would be a breaking change for the existing users. But I'm not sure.
Beta Was this translation helpful? Give feedback.
All reactions
-
But I think when envs_required parameter is set to False, from_* methods should load env interpolations as None and not the literal value if the environment variable is not set. I don't think this would be a breaking change for the existing users. But I'm not sure.
I tend to agree. I looked onto other yaml parsers in various systems and none of them leave environment variable markers unreplaced. I'm going to implement the same in Dependency Injector.
Beta Was this translation helpful? Give feedback.
All reactions
-
@hakanutku I released version 3.44.0
that adds envs_required
argument and interpolates undefined environment variables to empty value. For more information please check this documentation section: https://python-dependency-injector.ets-labs.org/providers/configuration.html#using-environment-variables-in-configuration-files
Also I've added raising of an exception on undefined environment variables for configuration provider in strict mode. Strict mode is described here: https://python-dependency-injector.ets-labs.org/providers/configuration.html#strict-mode-and-required-options
You can find full release notes in changelog: https://python-dependency-injector.ets-labs.org/main/changelog.html
Many thanks for raising this question. Also let me know if you have any other improvements. Would be glad to hear that.
Beta Was this translation helpful? Give feedback.
All reactions
-
This implementation covers all possible use cases and documentation is clear. I will upgrade to this version asap. Thanks again for the quick response and action.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Thank you for bring up the use case. Let me know if anything else pops up - I'll be glad to help.
Beta Was this translation helpful? Give feedback.