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
We should detect duplicate keys when loading configuration.yaml #1714
Comments
We could extend ordered dict and have it raise an error when overwriting a On Tue, Apr 5, 2016, 09:31 Jan Harkes notifications@github.com wrote:
|
Yes, but I assume we are overwriting at least some keys with coercion/validation, so we probably have to copy the write-once ordered dict to a normal ordered dict between yaml parsing and config validation. |
We could have our YAML parser method convert everything back before returning it (or maybe just have a boolean on our OrderedDict extension to unfreeze) |
I was thinking, we might already be doing the conversion because the groups were out of order for a bit after config validation was added. But I like the boolean to prevent key overwrites too. |
The group one was broken because at that time I did not understand voluptuous too well: https://github.com/balloob/home-assistant/blob/dev/homeassistant/components/group.py#L51 I guess that can be replaced with a simple dict validator. |
Oh, this is going to be nice. The nodes parsed from yaml are all passed into the class initializer and not through setattr. So we don't really need to prevent updates through setattr, just check for duplicates in |
Fixed! 🎉 |
Home Assistant release (
hass --version
):Python release (
python3 --version
):Component/platform:
homeassistant/util/yaml.py
Description of problem:
yaml parser accepts duplicate keys. So when someone forgets to add '-' to a list of mapping type entries there may be no error message or the error is confusing.
On gitter.im I noticed a message from @frelev who had an automation that didn't load correctly (see below configuration sample). The error message was quite unhelpful,
": extra keys not allowed @ data['condition'][0]['weekday']."
The reason we get this error message is because the second
platform: state
entry overwriteplatform: time
and the config validation for a state automation does not expect or accept a weekday entry. I can easily imagine two independentplatform:state
conditions that would be silently accepted, but not work correctly.Expected:
A duplicate key in a configuration file should trigger a load/parse error. But we cannot make the OrderedDict write-once for items so we probably need to introduce a proxy-object while loading the configuration that can catch whenever an existing key is about to be overwritten.
Problem-relevant
configuration.yaml
entries and steps to reproduce:Traceback (if applicable):
Additional info:
The text was updated successfully, but these errors were encountered: