Skip to content
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

oc:env interpolation w/default resolves to empty string when env var is missing #1179

Open
4 tasks
EtcetFelix opened this issue Jun 23, 2024 · 0 comments
Open
4 tasks
Labels
bug Something isn't working

Comments

@EtcetFelix
Copy link

Describe the bug
When using the built in interpolation resolver oc:env with a default value, the resolution is an empty string when the environment variable doesn't exist or is empty.

To Reproduce
I've attached the files to reproduce the issue below but here is the code:

from dataclasses import dataclass, field
from omegaconf import II, OmegaConf

@dataclass
class EnvironmentSettings:
    host: str = field(default=II("oc.env:REDIS_HOST,default_host"))

config = OmegaConf.structured(EnvironmentSettings)

print(config)
print(config.host)	# Should be 'default_host', but is empty string
print("done")

REDIS_HOST is not set in the environment on purpose.

Zip file with everything related to reproduce the issue:
testingOcEnvEmptyDefaultBug.zip

Expected behavior
According to the documentation:

You can specify a default value to use in case the environment variable is not set.

The expectation is that the output of the interpolation resolution is the default value. In this case, the output of config.host should be the string 'default_host'

Additional context

  • OmegaConf version: 2.3.0
  • Python version: Python 3.11.9
  • Operating system: Ubuntu 22.04.4 LTS
  • Please provide a minimal repro: testingOcEnvEmptyDefaultBug.zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant