Skip to content

Chore: Allow duplicate keys in dbt project yaml files#5254

Merged
vchan merged 1 commit intomainfrom
vchan/chore-relax-yaml-loading
Aug 29, 2025
Merged

Chore: Allow duplicate keys in dbt project yaml files#5254
vchan merged 1 commit intomainfrom
vchan/chore-relax-yaml-loading

Conversation

@vchan
Copy link
Contributor

@vchan vchan commented Aug 28, 2025

dbt allows duplicate keys, although newer versions emit a deprecation warning. This PR updates yaml loading of dbt projects to also allow duplicate keys and to keep the last value of duplicate keys, matching pyyaml's behavior.

@vchan vchan requested a review from a team August 28, 2025 19:40
@vchan vchan force-pushed the vchan/chore-relax-yaml-loading branch from 5d30bc5 to 59153ff Compare August 28, 2025 19:44
Comment on lines +37 to +39
def load_yaml(source: str | Path) -> t.Dict:
def load_yaml(source: str | Path, allow_duplicate_keys: bool = False) -> t.Dict:
try:
return load(source, render_jinja=False)
return load(source, render_jinja=False, allow_duplicate_keys=allow_duplicate_keys)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually need a flag in load_yaml itself here? Is there any call site where we actually don't want to allow duplicates? Curious if we'd match dbt's behavior in those cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just saw this. I made some larger changes for yaml loading to match dbt/pyyaml's behavior of keeping the last occurrence of duplicate keys. I think my changes also address your concerns though.

@vchan vchan force-pushed the vchan/chore-relax-yaml-loading branch from 59153ff to 9998db4 Compare August 29, 2025 21:29
@vchan vchan force-pushed the vchan/chore-relax-yaml-loading branch from 9998db4 to f17f73e Compare August 29, 2025 21:30
@vchan vchan enabled auto-merge (squash) August 29, 2025 21:46
@vchan vchan merged commit 61a65ac into main Aug 29, 2025
36 checks passed
@vchan vchan deleted the vchan/chore-relax-yaml-loading branch August 29, 2025 21:47
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