Fix UnicodeDecodeError in DefaultResponseHandler when response content is binary#68495
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
0302f44 to
b4ea670
Compare
b4ea670 to
8481bd8
Compare
dedc34b to
f51a35e
Compare
|
@davidnzhang Did you try passing |
|
@dabla Thanks for suggesting this - I just tested passing That said, I'd argue the case for this change still stands, as the |
Thx for testing this. Ok, once CI is green, we can merge this. |
7c033d3 to
557466d
Compare
thanks @dabla, are there any pending actions on me at this stage? |
557466d to
0feb2da
Compare
|
@dabla CI is green on the latest commit, happy for this to go in whenever you have a moment - thanks again for the review |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
What
DefaultResponseHandler.get_valuesuppressesJSONDecodeErrorwhenresponse.json()fails and falls back toresponse.contentor headers. This PR extends the suppression to also includeUnicodeDecodeErrorwhen the response body contains invalid bytes.Note: This seems to be specific to the
httpxtransport used by this response handler, which calls CPython'sjson.loads()without any additional exception handling. Thejson.loads()function can raise bothJSONDecodeErrorand `UnicodeDecodeError'.Why
Hooks that extend the
KiotaRequestAdapterHookmay call API endpoints that return binary responses. One such use case is to allow users to extend thePowerBIHookto support exporting reports to PDF. In these cases,response.json()raises a UnicodeDecodeError rather than a JSONDecodeError, causing the request to fail before reaching theresponse.contentfall through path. SuppressingUnicodeDecodeErroralongsideJSONDecodeErrorallows these binary responses to be handled correctly and returned as bytes.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Sonnet 4.6 following the guidelines
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.