One function
write_record in fastavro/fastavro
The author described this change as “fix bug where strict options were not catching extra fields”. It counts as a record because the check below fails on the code as it stood at 073da50af and passes on f8979588a, with nothing else changed between the two runs.
Projectfastavro/fastavro
Fix saved2022-09-09
Sharing licenceMIT · LICENSE
Change size+3 −6
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.
The change
| 3 | 3 | that they are declared. In other words, a record is encoded as just the | |
| 4 | 4 | concatenation of the encodings of its fields. Field values are encoded per | |
| 5 | 5 | their schema.""" | |
| 6 | - | if (options.get("strict") or options.get("strict_allow_default")) and len( | |
| 7 | - | datum | |
| 8 | - | ) > len(schema["fields"]): | |
| 9 | - | field_names = [field["name"] for field in schema["fields"]] | |
| 10 | - | extras = ", ".join(set(datum) - set(field_names)) | |
| 6 | + | extras = set(datum) - set(field["name"] for field in schema["fields"]) | |
| 7 | + | if (options.get("strict") or options.get("strict_allow_default")) and extras: | |
| 11 | 8 | raise ValueError( | |
| 12 | - | f"record contains more fields than the schema specifies: {extras}" | |
| 9 | + | f'record contains more fields than the schema specifies: {", ".join(extras)}' | |
| 13 | 10 | ) | |
| 14 | 11 | for field in schema["fields"]: | |
| 15 | 12 | name = field["name"] |
The check that tells the two apart
fail→pass·tests/test_fastavro.py::test_strict_allow_default_bug
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 it073da50afaec729f66caea357538417118ae7619
Broken version dated2022-08-29
Modulefastavro._write_py
Units changedwrite_record
Fingerprintccd8df198d76624a
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-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
- 2021-05-10parse_schema