-
-
Notifications
You must be signed in to change notification settings - Fork 318
Override config file from env variable using nested path #658
Copy link
Copy link
Closed
Labels
LazyIssueRelated to lazy evaluation such as @format etc...Related to lazy evaluation such as @format etc...bug
Description
Describe the bug
Not sure if it's working as expected but there is a difference between uppercase and lowercase when we try to override the config from a file settings.yaml when there is at least three nested levels
To Reproduce
- Having the following folder structure
Project structure
.
├── requirements.txt
├── settings.yaml
└── test_config.py
- Having the following
requirements.txt:
Project structure
python==3.9.6
dynaconf==3.1.5
pytest==6
- Having the following config files:
Config files
./settings.yaml
a:
b: foo
c:
d: hello- Having the following app code:
Code
./test_config.py
from dynaconf import Dynaconf
def new_settings():
settings = Dynaconf(
envvar_prefix="DYNACONF",
settings_files=['settings.yaml'],
)
print(f"{settings.a=}")
return settings
def test_nested_one_uppercase(monkeypatch):
monkeypatch.setenv("DYNACONF_A__B", "OK")
assert new_settings().a.b == "OK"
def test_nested_two_lowercase(monkeypatch):
monkeypatch.setenv("DYNACONF_a__b__c", "OK")
assert new_settings().a.b.c == "OK"
def test_nested_two_uppercase(monkeypatch):
monkeypatch.setenv("DYNACONF_A__B__C", "OK")
assert new_settings().A.B.C == "OK"
assert new_settings().a.b.c == "OK"- Executing under the following environment
Execution
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
pytestI used pytest with monkeypatch fixture to play with the lib but the issue is still there outside tests. I'm using MacOS but I also tried to run the script in a linux docker image
The last test is not working because the path is in uppercase and there are many nested levels
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.9.6, pytest-6.0.0, py-1.10.0, pluggy-0.13.1
collected 3 items
test_config.py ..F [100%]
=================================================================================================================================== FAILURES ===================================================================================================================================
__________________________________________________________________________________________________________________________ test_nested_two_uppercase ___________________________________________________________________________________________________________________________
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x102334a00>
def test_nested_two_uppercase(monkeypatch):
monkeypatch.setenv("DYNACONF_A__B__C", "OK")
assert new_settings().A.B.C == "OK"
> assert new_settings().a.b.c == "OK"
E AttributeError: 'str' object has no attribute 'c'
test_config.py:23: AttributeError
----------------------------------------------------------------------------------------------------------------------------- Captured stdout call -----------------------------------------------------------------------------------------------------------------------------
settings.a=<Box: {'B': {'C': 'OK'}, 'b': 'foo', 'c': {'d': 'hello'}}>
settings.a=<Box: {'B': {'C': 'OK'}, 'b': 'foo', 'c': {'d': 'hello'}}>
=========================================================================================================================== short test summary info ============================================================================================================================
FAILED test_config.py::test_nested_two_uppercase - AttributeError: 'str' object has no attribute 'c'
========================================================================================================================= 1 failed, 2 passed in 0.33s ==========================================================================================================================
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
LazyIssueRelated to lazy evaluation such as @format etc...Related to lazy evaluation such as @format etc...bug