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

Merging doesn't appear to work with load_file method but does with settings=[] in the constructor #1035

Open
Hammit opened this issue Dec 17, 2023 · 0 comments
Labels

Comments

@Hammit
Copy link

Hammit commented Dec 17, 2023

Bug Description
When I have multiple settings files I want to merge into one settings object, I can successfully merge using the settings kwarg in the Dynaconf constructor, however, when I try merging using load_file I don't get any merging behaviour.

To Reproduce

  1. Having the following folder structure

  2. Having the following config files:

Config files

./tests/configs/app.test.json

{
  "customers": {
    "a": {
      "apps": ["a", "b"],
      "databases": {
        "a": {
          "name": "b"
        },
        "b": {
          "name": "c"
        }
      }
    },
    "b": {
      "apps": ["a", "b"],
      "databases": {
        "a": {
          "name": "b"
        },
        "b": {
          "name": "c"
        }
      }
    }
  },
  "server": {
    "host": "example.org",
    "port": 443
  }
}

./tests/configs/app.merge.json

{
  "customers": {
    "a": {
      "apps": ["c", "d"]
    },
    "b": {
      "apps": ["e", "f"],
      "databases": {
        "name": "d"
      }
    },
    "c": {
      "apps": ["a"],
      "databases": {
        "name": "a"
      }
    }
  },
  "server": {
    "host": "example.org",
    "port": 443
  }
}
  1. Having the following app code:
Code

./app.py

from dynaconf import Dynaconf
from dynaconf import loaders
from dynaconf.utils.boxing import DynaBox


config = Dynaconf(
    merge_enabled=True,
    settings_files=["./tests/configs/app.test.json", './tests/configs/app.merge.json']
)


data = config.as_dict()
loaders.write('/tmp/config.json', DynaBox(data).to_dict(), merge=False)

config2 = Dynaconf(
    merge_enabled=True,
    settings_files=["./tests/configs/app.test.json"]
)

config2.load_file('./tests/configs/app.merge.json')

data = config2.as_dict()
loaders.write('/tmp/config2.json', DynaBox(data).to_dict(), merge=False)

Expected behavior
I would expect to be able to save both merged configs and have identical files. load_file should merge the same way that settings_files does

Environment (please complete the following information):

  • OS: WSL2 Ubuntu 22.04
  • Dynaconf Version: 3.2.4
  • No frameworks

Additional context
I have tried adding dynaconf_merge in various places in the file to merge without success
I can't get load_file to merge

@Hammit Hammit added the bug label Dec 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant