This is an automated email from the ASF dual-hosted git repository.

eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 5d4453dcaff MSgraph: fix UnicodeDecodeError in DefaultResponseHandler 
when response content is binary (#68495)
5d4453dcaff is described below

commit 5d4453dcaffa5a4964e4f681f0d806c076cf9a86
Author: davidnzhang <[email protected]>
AuthorDate: Thu Jul 2 05:23:45 2026 +1000

    MSgraph: fix UnicodeDecodeError in DefaultResponseHandler when response 
content is binary (#68495)
    
    * Add UnicodeDecodeError in DefaultResponseHandler fall through
    
    * Add unit test for DefaultResponseHandler for binary response content
    
    * Remove trailing whitespace
---
 .../src/airflow/providers/microsoft/azure/hooks/msgraph.py   |  2 +-
 .../azure/tests/unit/microsoft/azure/hooks/test_msgraph.py   | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git 
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
 
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
index 2f3bf3a4030..d1bc2f8deb1 100644
--- 
a/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
+++ 
b/providers/microsoft/azure/src/airflow/providers/microsoft/azure/hooks/msgraph.py
@@ -91,7 +91,7 @@ class DefaultResponseHandler(ResponseHandler):
 
     @staticmethod
     def get_value(response: Response) -> Any:
-        with suppress(JSONDecodeError):
+        with suppress(JSONDecodeError, UnicodeDecodeError):
             return response.json()
         content = response.content
         if not content:
diff --git 
a/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py 
b/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
index dab96656d43..8a6252da36e 100644
--- a/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
+++ b/providers/microsoft/azure/tests/unit/microsoft/azure/hooks/test_msgraph.py
@@ -676,6 +676,18 @@ class TestResponseHandler:
         assert isinstance(actual, bytes)
         assert actual == users
 
+    def test_default_response_handler_when_unicode_content(self):
+        dummy = load_file_from_resources(
+            dirname(__file__), "..", "resources", "dummy.pdf", mode="rb", 
encoding=None
+        )
+        response = mock_response(200, dummy)
+        response.json.side_effect = UnicodeDecodeError("utf-8", b"\xff", 0, 1, 
"invalid start byte")
+
+        actual = 
asyncio.run(DefaultResponseHandler().handle_response_async(response, None))
+
+        assert isinstance(actual, bytes)
+        assert actual == dummy
+
     def test_default_response_handler_when_no_content_but_headers(self):
         response = mock_response(200, headers={"RequestId": 
"ffb6096e-d409-4826-aaeb-b5d4b165dc4d"})
 

Reply via email to