Repository navigation
fix(parser): fall back to Python validation for non-JSON string payloads - #8699
Conversation
leandrodamascena
left a comment
There was a problem hiding this comment.
Thanks @azmi2409, confirmed with real Lambda runtime lines from one of our functions: START, END and REPORT now come back as strings with model=str, a JSON line next to them still parses, and a plain line against an object model still fails with the same json_invalid as before. Since this touches the shared string path I ran the other envelopes and parse() directly too. Two things change beyond the issue, both for the better: model=str with a JSON object payload now returns the string instead of failing, and bare ISO dates parse for model=datetime. I'll mention them in the release notes.
I'm approving now. This goes out in 3.40.0, so it will sit here for a while before I merge it. No rebase needed in the meantime, and you'll be credited in the release notes.
leandrodamascena
left a comment
There was a problem hiding this comment.
Re-approving after a small refactor on top: the nested fallback pushed parser/functions.py over the module complexity rank xenon enforces in CI, so I moved the string handling into _parse_string_payload. Same behaviour, 222 parser tests pass.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8699 +/- ##
========================================
Coverage 97.01% 97.01%
========================================
Files 321 321
Lines 16424 16431 +7
Branches 1484 1484
========================================
+ Hits 15933 15940 +7
Misses 350 350
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
083460d
into
aws-powertools:develop



Issue number: closes #8695
Summary
Changes
_parse_and_validate_event, whenvalidate_jsonrejects a string payload with aValidationError, fall back tovalidate_pythonon the raw value instead of failing immediately. If Python validation also fails, the original JSON error is re-raised, so genuinely invalid payloads still surface the same error as before.test_cloudwatch.py: plain-text Lambda runtime messages (START/END/REPORT plus an INFO line) are returned as-is withmodel=str, mixed JSON and plain-text messages are returned as-is withmodel=str, and plain text still raisesValidationErrorfor an object model.User experience
Before: parsing a real CloudWatch Logs subscription event with
CloudWatchLogsEnvelopeandmodel=strraised aValidationErroras soon as any log event was a plain-text Lambda runtime message (START, END, REPORT), even though the user asked for strings.After: those plain-text messages are returned as-is alongside JSON messages, JSON messages for object models still parse as before, and plain text for an object model still raises a
ValidationError.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.