You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: EventBridgeV2Envelope raises UnicodeDecodeError for application/octet-stream payloads that are not UTF-8 JSON #8666
The Parser envelope handles an application/octet-stream record the same way the EventBridgeV2Event data class does: the payload is available as bytes, so a bytes model gets the raw payload, and a model the payload doesn't match raises a ValidationError.
Current Behaviour
EventBridgeV2Envelope.parse (added in #8658) always runs payload.decode() on octet-stream bytes and passes the resulting str to _parse, which treats every str as JSON. Only octet-stream payloads that happen to be UTF-8 JSON work, which is the case test_envelope_parses_octet_stream_json_bytes covers.
Binary payloads (images, gzip, protobuf) raise a raw UnicodeDecodeError instead of a ValidationError, so handlers that catch ValidationError miss it.
Plain-text payloads fail validation even with model=bytes.
The data class returns the bytes for all of these, so the two APIs disagree on the same event.
For octet-stream bytes, try json.loads(payload) and fall back to passing the raw bytes to the model when it isn't JSON (json.loads raises ValueError for both invalid UTF-8 and invalid JSON). The JSON case keeps working as today, a bytes model gets the raw payload, and other models raise ValidationError. I have this ready with tests (all parser and data class tests pass) and am happy to open the PR.
Thanks @alphasafal, confirmed, and this one is on me: the decode() went in with the last push on #8658 and I only tested JSON bytes. Your approach is right, try JSON first and hand the raw bytes to the model otherwise, so bytes models get the payload and anything else raises ValidationError. It's yours. This has to land before 3.38.0 ships, so if you can open the PR in the next couple of days, great, otherwise I'll push the fix myself and credit you.
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
Activity
leandrodamascena commentedon Oct 25, 2026
Thanks @alphasafal, confirmed, and this one is on me: the
decode()went in with the last push on #8658 and I only tested JSON bytes. Your approach is right, try JSON first and hand the raw bytes to the model otherwise, sobytesmodels get the payload and anything else raisesValidationError. It's yours. This has to land before 3.38.0 ships, so if you can open the PR in the next couple of days, great, otherwise I'll push the fix myself and credit you.fix(parser): pass non-JSON octet-stream payloads to the model in Even…
alphasafal commentedon Oct 25, 2026
Thanks @leandrodamascena! PR is up: #8669. Try JSON first, fall back to the raw bytes, with tests for the binary, plain-text and object-model cases.
powertools-for-aws-oss-automation commentedon Oct 28, 2026
Warning
This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
fix(parser): pass non-JSON octet-stream payloads to the model in Even…
github-actions commentedon Oct 28, 2026
This is now released under 3.38.0 version!