One function
read_record in fastavro/fastavro
The author described this change as “fix issue with aliases when there is a new field in the new schema”. It counts as a record because the check below fails on the code as it stood at b4ff235ba and passes on b7959d715, with nothing else changed between the two runs.
Projectfastavro/fastavro
Fix saved2018-06-26
Sharing licenceMIT · LICENSE
Change size+2 −2
What the code was meant to do, written into the code itself as a docstring
A record is encoded by encoding the values of its fields in the order that they are declared. In other words, a record is encoded as just the concatenation of the encodings of its fields. Field values are encoded per their schema. Schema Resolution: * the ordering of fields may be different: fields are matched by name. * schemas for fields with the same name in both records are resolved recursively. * if the writer's record contains a field with a name not present in the reader's record, the writer's value for that field is ignored. * if the reader's record schema has a field that contains a default value, and writer's schema does not have a field with the same name, then the reader should use the default value from its field. * if the reader's record schema has a field with no default value, and writer's schema does not have a field with the same name, then the field's value is unset.
The change
| 47 | 47 | # fill in default values | |
| 48 | 48 | if len(readers_field_dict) > len(record): | |
| 49 | 49 | writer_fields = [f['name'] for f in writer_schema['fields']] | |
| 50 | - | for field_name, field in iteritems(readers_field_dict): | |
| 51 | - | if field_name not in writer_fields: | |
| 50 | + | for f_name, field in iteritems(readers_field_dict): | |
| 51 | + | if f_name not in writer_fields and f_name not in record: | |
| 52 | 52 | default = field.get('default') | |
| 53 | 53 | if 'default' in field: | |
| 54 | 54 | record[field['name']] = default |
The check that tells the two apart
fail→pass·tests/test_aliases.py::test_aliases_with_default_value_and_field_added
Check file tests/test_aliases.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before itb4ff235ba60642b766c00c7e50db83c0d686b45e
Broken version dated2018-06-21
Modulefastavro._read_py
Units changedread_record
Fingerprintd9ec9e43f40cb2bd
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in fastavro/fastavro
- 2024-02-13Fix aliases in schema resolution (#751)
- 2023-05-04fix namespace handling
- 2022-09-09write_record
- 2022-07-29fix issue with decoding records within maps
- 2022-05-21fix bug where records should match but they were not
- 2021-12-22fix issue with json decoding of complex types within maps