[bug] settings.local.toml tree overrides settings.toml
See original GitHub issueDescribe the bug If I define a conf variable “A.B.C” in one file and another conf variable “A.cousin.D” in another file, then “A.B.C” is erased.
To Reproduce Steps to reproduce the behavior:
- Having the following folder structure
Project structure
$ ls -alh
total 24K
drwxrwxr-x 2 user group 4,0K Jan 15 18:34 ./
drwxr-xr-x 109 user group 4,0K Jan 15 17:31 ../
-rw-rw-r-- 1 user group 75 Jan 15 18:27 dynaconf_test.py
-rw-rw-r-- 1 user group 16 Jan 15 18:34 requirements.txt
-rw-rw-r-- 1 user group 45 Jan 15 18:28 settings.local.toml
-rw-rw-r-- 1 user group 40 Jan 15 18:27 settings.toml
- Having the following config files:
Config files
$ echo $ENV_FOR_DYNACONF
and
/path/settings.toml
[default]
[development.A.B]
C = "1"
/path/settings.local.toml
[default]
[development.A.cousin]
D = "2"
/path/requirements.txt
dynaconf==v2.2.2
- Having the following app code:
Code
/path/dynaconf_test.py
from dynaconf import settings
print(settings.get('A').get('B').get('C'))
- Executing under the following environment:
Execution
$ python3 --version
Python 3.6.9
$ python3 -m pip install --user --upgrade pip
Requirement already up-to-date: ...
$ python3 -m pip install --user --upgrade virtualenv
Requirement already up-to-date:
$ python3 -m virtualenv -p python3 venv
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
[...]
Installing setuptools, pip, wheel...
done.
$ source venv/bin/activate
$ python3 -m pip install --quiet -r requirements.txt
Expected behavior Same as if I remove settings.local.toml or merge the two file together.
$ python dynaconf_test.py
1
Actual behavior
$ python dynaconf_test.py
Traceback (most recent call last):
File "dynaconf_test.py", line 3, in <module>
print(settings.get('A').get('B').get('C'))
AttributeError: 'NoneType' object has no attribute 'get'
Debug output
Debug Output
# export `DEBUG_LEVEL_FOR_DYNACONF=DEBUG` reproduce your problem and paste the output here
2020-01-15:18:44:51,460 DEBUG [base.py:86 - _read] toml_loader: /path/settings.toml
2020-01-15:18:44:51,460 DEBUG [base.py:159 - _read] toml_loader: settings.toml[default]{}
2020-01-15:18:44:51,460 DEBUG [base.py:159 - _read] toml_loader: settings.toml[development]{'A': {'B': {'C': '1'}}}
2020-01-15:18:44:51,460 DEBUG [base.py:86 - _read] toml_loader: /path/settings.local.toml
2020-01-15:18:44:51,460 DEBUG [base.py:159 - _read] toml_loader: settings.local.toml[default]{}
2020-01-15:18:44:51,460 DEBUG [base.py:159 - _read] toml_loader: settings.local.toml[development]{'A': {'cousin': {'D': '2'}}}
2020-01-15:18:44:51,461 DEBUG [base.py:902 - execute_loaders] Dynaconf executing: dynaconf.loaders.env_loader
2020-01-15:18:44:51,461 DEBUG [base.py:905 - execute_loaders] Loaded Files: ['/path/settings.toml', '/path/settings.local.toml']
2020-01-15:18:44:51,461 DEBUG [base.py:129 - _setup] Lazy Settings _setup ...
Traceback (most recent call last):
File "dynaconf_test.py", line 3, in <module>
print(settings.get('A').get('B').get('C'))
AttributeError: 'NoneType' object has no attribute 'get'
Environment (please complete the following information):
- OS: Linux Mint 19 (based on Ubuntu Bionic Beaver)
- Dynaconf Version: 2.2.2
- Frameworks in use: None
Additional context If I remove the file settings.local.toml then it works fine:
$ rm settings.local.toml
$ python dynaconf_test.py
1
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
[bug] settings.local.toml tree overrides settings.toml #284
Describe the bug If I define a conf variable "A.B.C" in one file and another ... [bug] settings.local.toml tree overrides settings.toml #284.
Read more >Using the config.toml File
The configuration engine reads and overrides variables in the following order: Driverless AI defaults: These are stored in a Python config ...
Read more >Configure Hugo
The user can choose to override that default with one or more site config files using the command-line --config switch. Examples: hugo --config...
Read more >Overrides - The rustup book
The rust-toolchain.toml file. The default toolchain. ... The per-directory overrides are stored in a configuration file in rustup 's home directory.
Read more >Configuration - The Cargo Book
By default, the variables specified will not override values that already exist in the environment. This behavior can be changed by setting the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is not a bug!
To have data merged it is needed to explicitly set a merge strategy
It can be a global
Or a local direct in the
settings.local.toml
file.And documentation is on https://www.dynaconf.com/merging/#local-configuration-files-and-merging-to-existing-data