Whole file
fastavro/fastavro
The author described this change as “fix issue with decoding records within maps”. It counts as a record because the check below fails on the code as it stood at c52cc9383 and passes on f50ac0ef7, with nothing else changed between the two runs.
Projectfastavro/fastavro
Fix saved2022-07-29
Sharing licenceMIT · LICENSE
Change size+12 −5
What the code was meant to do, written into the code itself as a save note
fix issue with decoding records within maps
The change
| 64 | 64 | # just has a single basic type | |
| 65 | 65 | return self._current | |
| 66 | 66 | ||
| 67 | - | def _push(self, symbol=None): | |
| 67 | + | def _push(self): | |
| 68 | 68 | self._stack.append((self._current, self._key)) | |
| 69 | + | ||
| 70 | + | def _push_and_adjust(self, symbol=None): | |
| 71 | + | self._push() | |
| 69 | 72 | if isinstance(self._current, dict) and self._key is not None: | |
| 70 | 73 | if self._key not in self._current: | |
| 71 | 74 | self._current = symbol.get_default() | |
| ⋯ | |||
| 81 | 84 | ||
| 82 | 85 | def do_action(self, action): | |
| 83 | 86 | if isinstance(action, RecordStart): | |
| 84 | - | self._push(action) | |
| 87 | + | self._push_and_adjust(action) | |
| 85 | 88 | elif isinstance(action, RecordEnd): | |
| 86 | 89 | self._pop() | |
| 87 | 90 | elif isinstance(action, FieldStart): | |
| ⋯ | |||
| 152 | 155 | ||
| 153 | 156 | def read_map_start(self): | |
| 154 | 157 | symbol = self._parser.advance(MapStart()) | |
| 155 | - | self._push(symbol) | |
| 158 | + | self._push_and_adjust(symbol) | |
| 156 | 159 | ||
| 157 | 160 | def read_object_key(self, key): | |
| 158 | 161 | self._key = key | |
| 159 | 162 | ||
| 160 | 163 | def iter_map(self): | |
| 161 | 164 | while len(self._current) > 0: | |
| 165 | + | self._push() | |
| 166 | + | for key in self._current: | |
| 167 | + | break | |
| 162 | 168 | yield | |
| 163 | - | del self._current[self._key] | |
| 169 | + | self._pop() | |
| 170 | + | del self._current[key] | |
| 164 | 171 | ||
| 165 | 172 | def read_map_end(self): | |
| 166 | 173 | self._parser.advance(MapEnd()) | |
| ⋯ | |||
| 168 | 175 | ||
| 169 | 176 | def read_array_start(self): | |
| 170 | 177 | symbol = self._parser.advance(ArrayStart()) | |
| 171 | - | self._push(symbol) | |
| 178 | + | self._push_and_adjust(symbol) | |
| 172 | 179 | self._key = None | |
| 173 | 180 | ||
| 174 | 181 | def read_array_end(self): | |
The check that tells the two apart
fail→pass·tests/test_json.py::test_json_with_map
Check file tests/test_json.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 itc52cc9383baf3a38c4296101675029b95400b7b3
Broken version dated2022-07-29
Modulefastavro.io.json_decoder
Units changedAvroJSONDecoder
Fingerprintf93e04dae24407de
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-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