fix(avro): advance the decoder when skipping an enum - #4009
Rodrigo-Palma wants to merge 1 commit into
Conversation
| assert actual == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("decoder_class", [StreamingBinaryDecoder, CythonBinaryDecoder]) |
There was a problem hiding this comment.
There's a list of AVAILABLE_DECODERS in tests/avro/test_reader.py that we should try to reuse
That'll involve moving that list to some shared file, but that way we can have future tests all share the same list of decoders.
There was a problem hiding this comment.
Moved the list to tests/avro/conftest.py, with a decoder_class fixture that parametrizes it, so these tests no longer carry their own copy.
I went with a fixture instead of importing the constant. CI runs pytest tests/avro/test_decoder.py on its own (python-ci.yml, and the cibuildwheel test command in the artifact workflows), and in that invocation the repository root is not on sys.path, so from tests.avro.conftest import AVAILABLE_DECODERS fails with ModuleNotFoundError: No module named 'tests'. I hit it locally before settling on the fixture. The existing from tests.conftest import ... imports have the same limitation and only work under python -m pytest. A fixture needs no import, so it works under either invocation.
test_decoder.py and test_reader.py still define their own copies. Direct parametrization takes precedence over a fixture of the same name, so they keep working untouched. Happy to migrate them in a follow-up if you would like: it is 22 decorators plus one itertools.product call, which felt like a separate change from this bug fix.
EnumReader.skip() was a no-op, so the enum's bytes stayed in the stream and the next field was decoded from them. Reading a manifest with the status field projected out returns wrong values for every field after it. Delegate to the wrapped reader, which is what read() already does.
1b8388f to
aaf1193
Compare
Closes #4006
Rationale for this change
EnumReader.skip()waspass, so skipping an enum field left its bytes in the stream and every field after it in the record was decoded from the wrong offset.read()already delegates to the wrapped reader;skip()now does the same.This is reachable from ordinary reads: the manifest entry schema starts with the
statusenum (field id 0), so any read that projectsstatusout decodes the rest of the entry from the enum's bytes.Are these changes tested?
Yes, two tests in
tests/avro/test_resolver.py, each parametrized overStreamingBinaryDecoderandCythonBinaryDecoder(4 cases, all failing before this change):test_enum_reader_skip_advances_the_decoder: after skipping, the next field reads its own value.test_enum_reader_skip_matches_read: reading and skipping leave the decoder at the same position.pytest tests/ -m unit --ignore=tests/integrationgives 4215 passed. The 9 failures intests/avro/test_decoder.pyare present identically on an unmodifiedmainin this checkout (a stale compiled Cython extension) and are unrelated to this change.Are there any user-facing changes?
Yes: reads that skip an enum field now return correct values instead of misaligned ones. No API change.