[
https://issues.apache.org/jira/browse/AVRO-2720?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17379506#comment-17379506
]
ASF subversion and git services commented on AVRO-2720:
-------------------------------------------------------
Commit f468930a1e119517491ed4e64b1bbd2906446b49 in avro's branch
refs/heads/master from Subhash Bhushan
[ https://gitbox.apache.org/repos/asf?p=avro.git;h=f468930 ]
AVRO-2720: Enhance AvroTypeException message to include field name (#1287)
* AVRO-2720: Enhance AvroTypeException message to include field name
The exception message now includes the field name on which the type exception
was raised.
Closes: AVRO-2720
* Increase Pypy 3.6 minimum speed to 5 secs
* Increase benchmark timings for both READ and WRITE
* Remove unnecessary sys import
* Change the global warnings filter to catch IgnoredLogicalType: With this
change, the ResourceWarning would just get messaged, and not raised as an
error, but the IgnoredLogicalType would get raised and then caught, and we can
test for it.
> Avro should display invalid field data on AvroTypeException
> -----------------------------------------------------------
>
> Key: AVRO-2720
> URL: https://issues.apache.org/jira/browse/AVRO-2720
> Project: Apache Avro
> Issue Type: Bug
> Components: python
> Reporter: Chelsea Dole
> Assignee: Subhash Bhushan
> Priority: Critical
>
> Calling "Validate"/"write" raises an AvroTypeException when the input "datum"
> does not fit the input "expected_schema". It would be useful for users if
> AvroTypeException specified which fields were not valid representations of
> the expected_schema, by adding additional information to the string printed
> when the error is thrown.
>
>
> {code:java}
> writer_schema = schema.parse("""\
> {"type": "record", "name": "Test",
> "fields": [{"name": "F", "type": "int"},
> {"name": "E", "type": "int"}]}""")
> datum_to_write = {'E': 5, 'F': 'Bad'}
> datum_writer = avro_io.DatumWriter(writer_schema)
> datum_writer.write(datum, encoder)
> {code}
>
> The last line of the above example ^ will throw an AvroTypeException, because
> field "F" isn't an int. If there are multiple fields with incompatible types,
> the message will only show the first field. Once it is fixed, it will throw
> another AvroTypeException with the second incompatible type field, and so on.
>
> *Current AvroTypeException Output:*
> {code:java}
> avro.io.AvroTypeException: The datum {'E': 5, 'F': 'Bad'} is not an example
> of the schema {
> "type": "record",
> "name": "Test",
> "fields": [{"type": "int", "name": "F"}, {"type": "int", "name":
> "E"}]}{code}
> *Suggested AvroTypeException Output:*
>
> {code:java}
> avro.io.AvroTypeException: Field 'F' with value 'Bad' has an unexpected type.
> The datum {'E': 5, 'F': 'Bad'} is not an example of the schema {
> "type": "record",
> "name": "Test",
> "fields": [{"type": "int", "name": "F"}, {"type": "int", "name": "E"}]}
> {code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)