Closed aisk closed 9 months ago
@coderabbitai review
The changes across various files introduce a strict_decode
parameter to functions and classes related to binary and compact protocols within a Python library, likely for handling Thrift serialization. This parameter enables strict decoding mode, where decoding errors result in exceptions. New test functions are added to ensure that enabling strict_decode
leads to the expected UnicodeDecodeError
when decoding operations encounter errors.
File Path | Change Summary |
---|---|
tests/test_aio_protocol_binary.py tests/test_aio_protocol_compact.py tests/test_protocol_binary.py tests/test_protocol_compact.py tests/test_protocol_cybinary.py |
Added new test functions test_strict_decode to verify behavior when strict_decode is True . |
thriftpy2/contrib/aio/protocol/binary.py thriftpy2/contrib/aio/protocol/compact.py thriftpy2/protocol/binary.py thriftpy2/protocol/compact.py thriftpy2/protocol/cybin/cybin.pyx |
Introduced strict_decode parameter to various functions and classes to control strict decoding behavior. |
🐇✨ In the realm of code where the data streams flow,
A rabbit hopped in, with astrict_decode
in tow.
"No more silent fails," it said with a cheer,
"For errors shall speak, whenever they're near!"
🎉🐰
The string field will be encoded into python string (formerly unicode in python2) via UTF-8 encoding, and if the field is not a valid UTF-8 string, current implementatiion will fallback to return the raw bytes.
As a result, there would be a pitfall for users: if someone don't validate the result type and just pass it to database or somewhere else, there would be a dirty data.
This change add a
strict_decode
flag when create protocol (or protocol factory) to progate theUnicodeDecodeError
to users so the PRC call will be failed as expected.The flag is not enabled by default for compatibility issue.
Protocols needs support:
Summary by CodeRabbit
New Features
Tests
Bug Fixes