loganasherjones / yapconf

Yet Another Python Configuration
http://yapconf.readthedocs.io/en/stable/
MIT License
18 stars 4 forks source link

Re-typing an item #56

Closed hazmat345 closed 6 years ago

hazmat345 commented 6 years ago

Pretty super corner-case here. Not sure exactly what's going on but hopefully you can make sense of it. It also may not be a yapconf problem.

Previously had spec item config that was a string. Awesome.

Changed config to be a dictionary with some items under it. I want one of those items, file, to inherit the previous value of config, so I list 'config' as a previous_name for file.

This seems to break when trying to migrate old configuration files - I think yapconf thinks (correctly!) that config should be a dictionary, but it's not in the old version.

I changed the config dictionary to be configuration in the new spec and things now seem to work. So this isn't pressing, just a little strange.

Here's what I have:

/home/mppatrick/.pyenv/versions/3.6.4/envs/integration-test/lib/python3.6/site-packages/yapconf/spec.py:272: in migrate_config_file
    always_update, update_defaults)
/home/mppatrick/.pyenv/versions/3.6.4/envs/integration-test/lib/python3.6/site-packages/yapconf/items.py:868: in migrate_config
    always_update, update_defaults)
/home/mppatrick/.pyenv/versions/3.6.4/envs/integration-test/lib/python3.6/site-packages/yapconf/items.py:249: in migrate_config
    value = self._search_config_for_possible_names(current_config)
/home/mppatrick/.pyenv/versions/3.6.4/envs/integration-test/lib/python3.6/site-packages/yapconf/items.py:448: in _search_config_for_possible_names
    value = self._search_config_for_fq_name(fq_name, config_to_search)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = Item(config.file, str), fq_name = 'config.file', config_to_search = 'dev_conf/config.json'

    def _search_config_for_fq_name(self, fq_name, config_to_search):
        names = fq_name.split(self.separator)
        for index, name in enumerate(names):
            if index == len(names) - 1:
>               return config_to_search.get(name, None)
E               AttributeError: 'str' object has no attribute 'get'
loganasherjones commented 6 years ago

Ah yeah. This makes sense why this would be happening. I'm not sure how exactly I can support a corner case like this. Not going to add this on the backlog for 0.3.0. Let me know if it becomes more important.

hazmat345 commented 6 years ago

That's totally fair. Feel free to close this if it's not easily fixable. Might be worth adding a warning to the docs telling people not to do this :smile:

loganasherjones commented 6 years ago

This is interesting for posterity, but I plan on closing this. I have no immediate plans for a more complicated migration strategy for yapconf. When I do, this issue will be addressed by this migration strategy.