Skip to content

yaml check complains about valid use of multiple anchors & aliases << #412

@kowalcj0

Description

@kowalcj0

Hi,

We do use anchors & aliases <<: * quite extensively in our CircleCI yaml config.
Unfortunately check-yaml (or rather ruamel.yaml) complains about duplicated << keys, which actually aren't duplicated.
Let's take this job definition as an example:

jobs:
  setup_env_for_smoke_tests:
    <<: *machine_python3
    working_directory: ~/directory-tests
    <<: *steps_setup_env_for_smoke_tests

When I run pre-commit run --all-files without args: [--unsafe], I'm going to get this error:

    raise DuplicateKeyError(*args)
ruamel.yaml.constructor.DuplicateKeyError: while constructing a mapping
  in ".circleci/config.yml", line 254, column 5
found duplicate key "<<"
  in ".circleci/config.yml", line 256, column 5
To suppress this check see:
   http://yaml.readthedocs.io/en/latest/api.html#duplicate-keys

I had a look at recommended doc page https://yaml.readthedocs.io/en/latest/api.html#duplicate-keys and ruamel.yaml has an option to allow allow_duplicate_keys, unfortunately check_yaml.py does not support it.

As a workaround I allowed unsafe constructs, but it doesn't look good:

    -   id: check-yaml
        args: [--unsafe]

In theory we can "merge keys" but it's rather an ugly solution:

Further reading:

Thanks

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions