Adding subsections automatically does not work for all sources
Problem
By default, when adding nested keys to a config and the parent keys do not exist, a KeyError or AttributeError is raised (depending on dot or dict notation). On instantiation the "auto_subsection" parameter can be set to True so that configstacker will instead automatically add those missing parent keys. However, this does not work for environment variables.
Minimal example:
env = configstacker.Environment('MYAPP', auto_subsection=True)
# add nested key 'b' while 'a' is missing
env.a.b = 10
<Traceback>
...
AttributeError: 'Environment' object has no attribute 'a'
Reason
The reason for that is because configstacker.sources.base.DefaultValueMixin just adds each missing parent one after another as an empty dict. While persisting these changes to the source those still empty dictionaries cannot be reflected as in the variable names. In the next line, when DefaultValueMixin tries to return the newly added subsection, it cannot be found.
Possible Solutions
There are basically two ways to solve that. Either each source handler takes care of that individually or the DefaultValueMixin does it and solves this problem for all sources at once (preferred). In both cases instead of writing back the newly added keys immediately they are temporarily cached. As soon as the last key value pair is added the cache will be persisted.