One function
write_union in fastavro/fastavro
The author described this change as “fix bug in union writing with tuple notation”. It counts as a record because the check below fails on the code as it stood at a6f182524 and passes on 0e8fa9051, with nothing else changed between the two runs.
Projectfastavro/fastavro
Fix saved2021-02-14
Sharing licenceMIT · LICENSE
Change size+3 −2
What the code was meant to do, written into the code itself as a docstring
A union is encoded by first writing a long value indicating the zero-based position within the union of the schema of its value. The value is then encoded per the indicated schema within the union.
The change
| 7 | 7 | if isinstance(datum, tuple): | |
| 8 | 8 | (name, datum) = datum | |
| 9 | 9 | for index, candidate in enumerate(schema): | |
| 10 | - | if extract_record_type(candidate) == "record": | |
| 10 | + | extracted_type = extract_record_type(candidate) | |
| 11 | + | if extracted_type == "record": | |
| 11 | 12 | schema_name = candidate["name"] | |
| 12 | 13 | else: | |
| 13 | - | schema_name = candidate | |
| 14 | + | schema_name = extracted_type | |
| 14 | 15 | if name == schema_name: | |
| 15 | 16 | best_match_index = index | |
| 16 | 17 | break |
The check that tells the two apart
fail→pass·tests/test_fastavro.py::test_tuple_writer_picks_correct_union_path
Check file tests/test_fastavro.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 ita6f18252415f23ad1ce06ce019ac2f1d9feef0aa
Broken version dated2021-02-06
Modulefastavro._write_py
Units changedwrite_union
Fingerprint59d4ab4c6d099d0f
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