Skip to content

[Variant] Add flag in ObjectBuilder to control validation behavior on duplicate field write #7777

Open
@friendlymatthew

Description

@friendlymatthew

The above would certainly work, in the sense of producing a valid variant object. My only concern would be that the scenario almost certainly arises due to user error (which is quite different from a generic map or set), and silently tolerating that error isn't necessarily doing the user any favors in the long run. They'll just discover at read time that they lost data, instead of fast-failing at write time. We can probably get away with either approach -- silently replacing or loudly complaining -- I just want to be sure we make the choice intentionally.

Maybe we could have some flag that controls the validation behavior? Something like

let mut builder = VariantBuilder::new();
let mut obj = builder.new_object()
  // specify that an error should be thrown on repeated fields
  .with_validate_unique_fields()
...
obj.finish()?; // this throws error if there were repeated fields

That way people could check for errors programmatically if they wanted to and could disable the checking if they didn't care 🤔

Originally posted by @alamb in #7741 (comment)

Describe the solution you'd like

Allow the user to configure insert validation behavior.

Metadata

Metadata

Assignees

Labels

enhancementAny new improvement worthy of a entry in the changeloggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions