-
Notifications
You must be signed in to change notification settings - Fork 6
Phase 20.3: route every shared portal client through the JSON decode guard #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
74c5095
fix(errors): route every shared portal client through the decode guard
mariomeyer 09b101a
docs(20.3): roadmap entry, ERR-05, and the corrected decode rule
mariomeyer bd8e9aa
docs(20.3): verification report; retire the stale Drug/Nutrient caveat
mariomeyer 30352d4
fix(errors): treat undecodable bytes as upstream failure, not caller …
mariomeyer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.planning/phases/20.3-route-every-shared-portal-client-through-the-json-decode-gua/.gitkeep
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an upstream returns bytes that are not valid UTF-8/16/32 (for example
b"\xff"), bothresponse.json()andjson.loads(content)raiseUnicodeDecodeError, notjson.JSONDecodeError. BecauseUnicodeDecodeErroris also aValueError, it escapes these new guards and the Saskatchewan/Manitobaexcept ValueErrorarms still report the upstream failure asINVALID_INPUT, contrary to the purpose of this change. Convert this decode failure tohttpx.DecodingErrorin both helpers as well.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed and fixed in 30352d4. You are right, and I had considered
UnicodeDecodeErrorearlier in this work and talked myself out of it as speculation — it is not speculative.Verified your example before acting:
json.loads(b"\xff")andresponse.json()onb"\xff"both raiseUnicodeDecodeError, notJSONDecodeError. (My first probe usedb"\xff\xfe\x00bad", which is a valid UTF-16 BOM, so it decoded and then failed asJSONDecodeError— that nearly led me to dismiss the report. Your exact byte was the one that mattered.)Two changes:
decode_jsonanddecode_json_bytesnow catch(json.JSONDecodeError, UnicodeDecodeError), as you asked.shared/envelope.py:upstream_guardhad the identical arm ordering, and I confirmed it returnedINVALID_INPUTfor a rawUnicodeDecodeErrorbefore fixing. That is the live path for every client that calls.json()itself — drug_database, nutrient_file, recalls, ckan, statcan — so the same masking existed there.I also made the regression test assert the general property rather than enumerate exception types:
test_decode_helpers_never_raise_a_valueerror_subclassfeeds four malformed-body shapes and asserts nothing escaping the helpers is aValueErrorsubclass. Enumerating types is what let this through; the property does not have that failure mode.Non-vacuity confirmed by reverting
shared/http.py— all 4 new tests fail.