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

load() with multipe configs doesn't "merge" it overwrites #399

Open
andrewebdev opened this issue Jun 5, 2022 · 0 comments
Open

load() with multipe configs doesn't "merge" it overwrites #399

andrewebdev opened this issue Jun 5, 2022 · 0 comments

Comments

@andrewebdev
Copy link

andrewebdev commented Jun 5, 2022

Not sure if this was intended, but if you use load() with a list of config files, the code overwrite the base config keys instead of merging the dictionaries. This fits my workflow where I may have a base configuration, and then have a local override based on the environment I'm working on. This override should be able to override a single setting nested amongst others, without losing other settings.

I ended up loading the two files separately and then writing my own merge function:

def merge_dicts(base, merge_dict):
    """
    Safely merges nested dictionaries
    """
    for k, v in merge_dict.items():
        if isinstance(v, collections.abc.Mapping):
            base[k] = merge_dicts(base.get(k, {}), v)
        else:
            base[k] = v
    return base

Maybe this something like this should be included in decode.load()? Maybe as a merged=True option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant