Skip to content

Detect duplicate keys of mapping nodes #141

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

Merged
merged 4 commits into from
Feb 28, 2025
Merged

Conversation

sstroemer
Copy link
Contributor

This (at least partially) fixes #140 by checking for the existence of a key before inserting it into mapping, which requires the dicttype to implement setindex! (since it's inside the try catch I thought it was safe to just assume that all "proper dicttypes" should support that, would otherwise just get caught).

I suppose that "bug fix" could be potentially seen as breaking change to some code bases (but maybe a good one?), which is why I've opted to do it in a non-breaking way, defaulting to not throwing and sticking to the previous behavior. Could be worth to consider always throwing here though...

Copy link
Member

@kescobo kescobo left a comment

Choose a reason for hiding this comment

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

I'm fine with this approach, but given the clarity of the spec, this does seem like a clear bug, which IMO could be fixed in a patch release even if it breaks existing code - that code shouldn't work.

That said, I can also see the argument for this approach which gives folks a flashing red light, but doesn't stop their code from running. I don't feel strongly one way or the other.

…epending on `strict_unique_keys`

Co-authored-by: Kevin Bonham <[email protected]>
@GunnarFarneback
Copy link
Contributor

GunnarFarneback commented Jun 12, 2024

Depending on implementation details, this may or may not conflict with the override functionality of merge tags, https://yaml.org/type/merge.html.

Edit: It's probably fine since there's a merge test which doesn't fail.

@JTHesse
Copy link

JTHesse commented Feb 28, 2025

Can this be merged?

@kescobo kescobo merged commit ffe5319 into JuliaData:master Feb 28, 2025
20 checks passed
sjdaines added a commit to PALEOtoolkit/PALEOboxes.jl that referenced this pull request Mar 1, 2025
Update Project.toml [compat] to restrict YAML version to
  YAML = "0.4.7 - 0.4.12"

This is a workaround for a breaking change in YAML v0.4.13 that
breaks merge keys
JuliaData/YAML.jl#141
JuliaData/YAML.jl#243
sjdaines added a commit to PALEOtoolkit/PALEOboxes.jl that referenced this pull request Mar 1, 2025
Update Project.toml [compat] to restrict YAML version to
YAML = "0.4.7 - 0.4.12"

This is a workaround for a breaking change in YAML v0.4.13 that breaks merge keys
PR with the change is: JuliaData/YAML.jl#141
Reported as issue: JuliaData/YAML.jl#243
@mikyvolek
Copy link

Apologies if this is not the right place to raise this but: would it be possible to expose the strict_unique_keys parameter in the API? I would prefer for YAML.load_file() to actually throw an error.

@GunnarFarneback
Copy link
Contributor

Depending on implementation details, this may or may not conflict with the override functionality of merge tags, https://yaml.org/type/merge.html.

Oh, well, it definitely does interfere.

Edit: It's probably fine since there's a merge test which doesn't fail.

It doesn't fail but produces lots of @error messages in the log.

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.

Duplicate keys in mapping
5 participants