-
Notifications
You must be signed in to change notification settings - Fork 418
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
Throw an error / refuse to load if apps.yaml has a duplicate top-level key #1899
Comments
As you guessed, this is a limitation of YAML. By the time this situation gets through to AD code, the YAML libraries have already ignored one of the entries as a duplicate and we never get to see it.
|
Thanks for taking a look! What do you think of the approach of customizing the yaml class UniqueKeyLoader(yaml.SafeLoader):
def construct_mapping(self, node, deep=False):
mapping = set()
for key_node, value_node in node.value:
if ':merge' in key_node.tag:
continue
key = self.construct_object(key_node, deep=deep)
if key in mapping:
raise ValueError(f"Duplicate {key!r} key found in YAML.")
mapping.add(key)
return super().construct_mapping(node, deep)
# other code
yaml_dic=yaml.load(yaml_file,Loader=UniqueKeyLoader) Poking around AppDaemon's code, would that fit into By the way I'm really enjoying AppDaemon, very easy to get started, helpful examples, and flexible enough to handle as much complexity as I've come up with so far. |
Is there an existing feature request for this?
Your feature request
A couple times I've accidentally repeated the same apps.yaml top-level key. AppDaemon picks one and ignores the other (maybe this is just YAML load behavior). This has led to confusing errors for me, such as a new app working fine but an old one no longer working somewhat mysteriously until I figure out what I did. I would rather AppDaemon treat this as an error and refuse to load the new apps.yaml file.
Example:
In the above case, I would like an error, but AppDaemon loads the file with only one
my_app
.PyYAML has issues open for this since 2016 so I doubt we'll see a library solution, but there are a number of workarounds mentioned like creating a customized loader.
The text was updated successfully, but these errors were encountered: