[
https://issues.apache.org/jira/browse/AVRO-3229?focusedWorklogId=698188&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-698188
]
ASF GitHub Bot logged work on AVRO-3229:
----------------------------------------
Author: ASF GitHub Bot
Created on: 18/Dec/21 02:45
Start Date: 18/Dec/21 02:45
Worklog Time Spent: 10m
Work Description: kojiromike opened a new pull request #1433:
URL: https://github.com/apache/avro/pull/1433
Raise an InvalidDefault exception when attempting to parse an enumschema
with a default value that isn't one of the enum's symbols.
### Jira
- [x] Addresses [AVRO-3229](https://issues.apache.org/jira/browse/AVRO-3229)
- [x] References it in the PR title.
- [x] Adds no dependency
### Tests
- [x] Adds a unit test to ensure the schema is invalid as expected.
### Commits
- [x] Commits all reference the Jira issue.
- [x] Commits follow the guidelines from "[How to write a good git commit
message](https://chris.beams.io/posts/git-commit/)":
1. Subject is separated from body by a blank line
1. Subject is limited to 50 characters (not including Jira issue reference)
1. Subject does not end with a period
1. Subject uses the imperative mood ("add", not "adding")
1. Body wraps at 72 characters
1. Body explains "what" and "why", not "how"
### Documentation
- [x] N/A
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 698188)
Remaining Estimate: 0h
Time Spent: 10m
> Python Avro doesn't validate the default value of an enum field
> ---------------------------------------------------------------
>
> Key: AVRO-3229
> URL: https://issues.apache.org/jira/browse/AVRO-3229
> Project: Apache Avro
> Issue Type: Bug
> Components: python
> Affects Versions: 1.10.2
> Environment: python --version
> Python 3.9.5
> pip freeze | grep avro
> avro==1.10.2
> Reporter: Augusto Hack
> Priority: Trivial
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> The following schema is invalid for Java (it fails to compile), because the
> default value is not a valid symbol:
>
> {code:java}
> {
> "type": "record",
> "name": "test_schema",
> "fields": [
> {
> "name": "test_enum",
> "type": {
> "name": "test_enum_type",
> "type": "enum",
> "symbols": [
> "NONE"
> ],
> "default": "UNKNOWN"
> }
> }
> ]
> }
> {code}
> This matches the behavior documented in the spec:
>
> {quote}default: A default value for this enumeration, used during resolution
> when the reader encounters a symbol from the writer that isn't defined in the
> reader's schema (optional). The value provided here must be a JSON *string
> that's a member of the symbols array*. See documentation on schema resolution
> for how this gets used.
> {quote}
> But the same schema is silently accepted by the python library (although the
> writer doesn't allow the invalid value to be produced):
> {code:java}
> import avro.schema
> from avro.datafile import DataFileReader, DataFileWriter
> from avro.io import DatumReader, DatumWriter
> with open("test.avsc", "rb") as handler:
> schema = avro.schema.parse(handler.read())
> DATA_FILE = "test.avro"
> with open(DATA_FILE, "wb") as handler:
> writer = DataFileWriter(handler, DatumWriter(), schema)
> writer.append({"test_enum": "NONE"})
> # writer.append({"test_enum": "UNKNOWN"})
> # writer.append({})
> writer.close()
> with open(DATA_FILE, "rb") as handler:
> for user in DataFileReader(handler, DatumReader()):
> print(user)
> {code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)