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.

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

6464 # just has a single basic type
6565 return self._current
6666
67- def _push(self, symbol=None):
67+ def _push(self):
6868 self._stack.append((self._current, self._key))
69+
70+ def _push_and_adjust(self, symbol=None):
71+ self._push()
6972 if isinstance(self._current, dict) and self._key is not None:
7073 if self._key not in self._current:
7174 self._current = symbol.get_default()
8184
8285 def do_action(self, action):
8386 if isinstance(action, RecordStart):
84- self._push(action)
87+ self._push_and_adjust(action)
8588 elif isinstance(action, RecordEnd):
8689 self._pop()
8790 elif isinstance(action, FieldStart):
152155
153156 def read_map_start(self):
154157 symbol = self._parser.advance(MapStart())
155- self._push(symbol)
158+ self._push_and_adjust(symbol)
156159
157160 def read_object_key(self, key):
158161 self._key = key
159162
160163 def iter_map(self):
161164 while len(self._current) > 0:
165+ self._push()
166+ for key in self._current:
167+ break
162168 yield
163- del self._current[self._key]
169+ self._pop()
170+ del self._current[key]
164171
165172 def read_map_end(self):
166173 self._parser.advance(MapEnd())
168175
169176 def read_array_start(self):
170177 symbol = self._parser.advance(ArrayStart())
171- self._push(symbol)
178+ self._push_and_adjust(symbol)
172179 self._key = None
173180
174181 def read_array_end(self):

The check that tells the two apart

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