[ruby] Keep all union record errors and tag them accordingly #2062
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I wasn't able to create an issue in JIRA, since I don't seem to be able to request a user. I am a first time contributor, apologies in case something is not precise enough
What is the purpose of the change
Improving validation errors for unions of records
When no valid union is found, this line selects the first error that it finds. If there would be 3 different possible schemas, there are 3
failures
, however only the first one will be considered.avro/lang/ruby/lib/avro/schema_validator.rb
Line 199 in fc2a4e0
The returned error also does not give any context of the error, only about the invalid fields.
As an example, consider we have 3 types of adresses
PersonalAddress
,WorkAddress
,SecondAddress
and we made a typo: We used the fieldcompan
instead ofcompany
, which belongs toWorkAddress
. No type will work for the union.{ "compan" => "acme inc.", "some_other_field" => "something else" }
Since
PersonalAddress
is the first type that fails, the errors ofPersonalAddress
are the ones that will be returned. SincePersonalAddress
has different structure, all fields that aren't the same as inWorkAddress
will be shown as errors. The error will be something likeThis gets very confusing because 1) The issue is that no union matched 2) It is not clear because only one of the error is displayed.
I'd be happy if this is fix in some other fashion, this is just an example. With we replace
detect
withselect
and we add the schema name to the error. Then the error will be like:Verifying this change
This change added tests and can be verified as follows:
Documentation