Skip to content
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

util/yaml: warn on duplicate keys in mappings #1451

Merged

Conversation

Bastian-Krause
Copy link
Member

@Bastian-Krause Bastian-Krause commented Jul 26, 2024

Description
When adding drivers/resources to an environment config or resources to an exporter config, users can stumble upon redundant keys. The resulting errors are not obvious, the last key simply overrides any previous entries with the same key.

In order to make these config errors more obvious, emit a warning when duplicate keys are detected in mappings.

Checklist

  • Tests for the feature
  • PR has been tested

@Bastian-Krause Bastian-Krause force-pushed the bst/yaml-duplicate-keys branch 2 times, most recently from b7e3dee to 1890cb1 Compare July 27, 2024 09:43
When adding drivers/resources to an environment config or resources to
an exporter config, users can stumble upon redundant keys. The resulting
errors are not obvious, the last key simply overrides any previous
entries with the same key.

In order to make these config errors more obvious, emit a warning when
duplicate keys are detected in mappings.

Signed-off-by: Bastian Krause <[email protected]>
@Bastian-Krause Bastian-Krause changed the title util/yaml: warn on duplicate keys in mapping tags util/yaml: warn on duplicate keys in mappings Jul 27, 2024
Copy link
Member

@SmithChart SmithChart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on the setup where I ran into this issue recently.

I guess this warning would have made my problem really obvious:

/(...)/labgrid-lxatac/venv/lib/python3.11/site-packages/labgrid/util/yaml.py:26: UserWarning: lxatac-ptx.yaml: previous entry with duplicate YAML dictionary key 'LXAIOBusPIODriver' overwritten

pyyaml seems to had a discussion on if they want to solve this at least back tot 2018: yaml/pyyaml#165
But it does not look like the project is willing to provide an upstream solution for this situation.

LGTM

@Bastian-Krause
Copy link
Member Author

Before merging, let me check if this also works with templated exporter configs.

@Bastian-Krause
Copy link
Member Author

Works also with templated configs.

@Bastian-Krause Bastian-Krause merged commit 64b995f into labgrid-project:master Jul 30, 2024
9 checks passed
@Bastian-Krause Bastian-Krause deleted the bst/yaml-duplicate-keys branch July 30, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants