question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] settings.local.toml tree overrides settings.toml

See original GitHub issue

Describe 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:

  1. 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
  1. 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
  1. Having the following app code:
Code

/path/dynaconf_test.py

from dynaconf import settings

print(settings.get('A').get('B').get('C'))
  1. 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:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rochacbrunocommented, Oct 1, 2020

This is not a bug!

To have data merged it is needed to explicitly set a merge strategy

It can be a global

settings = Dynaconf(
    settings_file="settings.toml",
    environments=True,
    merge_enabled=True  # this enabled global merge of all files
)


Or a local direct in the settings.local.toml file.

# to explicitly merge a file into existing data it should contain merge token
dynaconf_merge = true

[default]

[development.A.cousin]
D = "2"

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found