You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
What do you think of the approach of customizing the yaml Loader? Here's an example from a gist discussion thread:
classUniqueKeyLoader(yaml.SafeLoader):
defconstruct_mapping(self, node, deep=False):
mapping=set()
forkey_node, value_nodeinnode.value:
if':merge'inkey_node.tag:
continuekey=self.construct_object(key_node, deep=deep)
ifkeyinmapping:
raiseValueError(f"Duplicate {key!r} key found in YAML.")
mapping.add(key)
returnsuper().construct_mapping(node, deep)
# other codeyaml_dic=yaml.load(yaml_file,Loader=UniqueKeyLoader)
Poking around AppDaemon's code, would that fit into utils.read_yaml_config, as a possible replacement for Loader=yaml.SafeLoader (which gets called from app_management.py) ?
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: