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.

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

4747 # fill in default values
4848 if len(readers_field_dict) > len(record):
4949 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:
5252 default = field.get('default')
5353 if 'default' in field:
5454 record[field['name']] = default

The check that tells the two apart

failpass·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