Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Required environment variables interpolation for YAML and INI files #457

hakanutku started this conversation in Ideas
Discussion options

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.

You must be logged in to vote

Replies: 1 comment 6 replies

Comment options

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.

You must be logged in to vote
6 replies
Comment options

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.

Comment options

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.

Comment options

@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.

Comment options

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.

Comment options

Thank you for bring up the use case. Let me know if anything else pops up - I'll be glad to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /