UnboundLocalError when getting config from environment vars only
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
oslo.config |
Fix Released
|
Medium
|
Stephen Finucane |
Bug Description
Getting the following error under the following conditions
* Option set via env variable AND
* option *not* defined in the config file AND
* the validation of its value fails (e.g. as the defined regex does not match).
It works as expected when a the option is defined in the config file. More details in the reproduce section
```
Traceback (most recent call last):
File "test.py", line 19, in <module>
print(
File "/home/
return self._conf.
File "/home/
value, loc = self._do_get(name, group, namespace)
File "/home/
opt.name, alt_loc, str(ve))
UnboundLocalError: local variable 'alt_loc' referenced before assignment
```
Reproduce
=========
Save the following script "test.py"
```
from __future__ import print_function
from oslo_config import cfg
from os import environ
g = cfg.OptGroup(
foo = cfg.StrOpt("foo", regex="^[a-z].*$")
cfg.CONF.
environ[
cfg.CONF()
print("### Correct value set via env variable")
print(cfg.
environ[
cfg.CONF()
print("### Invalid value set via env variable")
print(cfg.
del environ[
cfg.CONF()
print("### Invalid value from conf file")
print(cfg.
```
store the following config file "config.cfg"
```
[group]
foo=BAR
```
Now run the script
`python test.py --config-file config.cfg`
-> as expected, getting a `ConfigFileValu
now clear the config.cfg file and run the command again
echo "" > config.cfg
`python test.py --config-file config.cfg`
-> Result: `UnboundLocalError: local variable 'alt_loc' referenced before assignment`
-> Expectation: `oslo_config.
Version
-------
python 2.7.15rc1
oslo.config==6.11.0
description: | updated |
description: | updated |
Changed in oslo.config: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
assignee: | nobody → Stephen Finucane (stephenfinucane) |
Fix proposed to branch: master /review. opendev. org/724880
Review: https:/