GitHub
10/26/2026, 10:17 AMmeltano config set (and anything else that writes meltano.yml back) expanded YAML anchors and aliases, so a value defined once with &anchor and reused with *anchor was written out in full at every use.
The cause is in Canonical.as_canonical, which rebuilt every mapping and sequence as a new object. An alias is the same Python object appearing twice in the loaded tree. Rebuilding gave each occurrence its own copy, so the dumper had nothing left to turn back into an alias, and it also dropped the anchor.
This keeps one canonical copy per anchored node while converting, so every alias still points at the same object and the anchor is written back. Nodes without an anchor are copied as before, so nothing that merely shares an object gets anchors it never had.
Merge keys (<<: *anchor) are not covered by this change and behave as before. They go through separate handling in ruamel and I'd rather do them on their own.
Tests:
• test_preserve_anchors_and_aliases and test_canonical_without_anchors_has_independent_copies in tests/meltano/core/behavior/test_canonical.py
• test_config_set_preserves_yaml_anchors in tests/meltano/cli/test_config.py, which runs meltano config set on a project with mapping and sequence anchors
The anchor tests fail without the change and pass with it.
Checklist
• I have read the contribution guide
Was generative AI tooling used to co-author this PR?
• Yes (please specify the tool below)
Generated-by: Claude Code following the agentic coding guidelines
Related Issues
• Closes #7206
Summary by Sourcery
Preserve YAML anchors and aliases when writing canonicalized Meltano configuration files.
Bug Fixes:
• Preserve YAML anchors and aliases when canonicalized configuration is written back, preventing anchored mappings and sequences from being expanded.
Enhancements:
• Maintain independent copies for ordinary shared objects while reusing canonical copies only for explicitly anchored YAML nodes.
Tests:
• Add unit and CLI coverage for preserving mapping and sequence anchors through canonicalization and meltano config set.
meltano/meltano