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 7c74b2a4203 Add tests to test whether snowflake sql API handles 
invalid JSON (#52118)
7c74b2a4203 is described below

commit 7c74b2a4203bf44bbff135bde5a071833d5a3500
Author: Aryan Khurana <[email protected]>
AuthorDate: Tue Jun 24 00:35:18 2025 -0400

    Add tests to test whether snowflake sql API handles invalid JSON (#52118)
---
 .../unit/snowflake/hooks/test_snowflake_sql_api.py | 46 ++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git 
a/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake_sql_api.py 
b/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake_sql_api.py
index 410588a7a71..8e610e2fd75 100644
--- a/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake_sql_api.py
+++ b/providers/snowflake/tests/unit/snowflake/hooks/test_snowflake_sql_api.py
@@ -1179,3 +1179,49 @@ class TestSnowflakeSqlApiHook:
             await hook._make_api_call_with_retries_async("PATCH", API_URL, 
HEADERS)
         # No HTTP call should be made
         assert mock_async_request.__aenter__.call_count == 0
+
+    @pytest.mark.asyncio
+    async def 
test_make_api_call_with_retries_async_json_decode_error_prevention(self, 
mock_async_request):
+        """
+        Test that _make_api_call_with_retries_async calls raise_for_status() 
before response.json()
+        to prevent JSONDecodeError when response is not valid JSON.
+        """
+        hook = SnowflakeSqlApiHook(snowflake_conn_id="test_conn")
+
+        failed_response = mock.MagicMock()
+        failed_response.status = 500
+        failed_response.json = AsyncMock(side_effect=ValueError("Invalid 
JSON"))
+        failed_response.raise_for_status.side_effect = 
aiohttp.ClientResponseError(
+            request_info=mock.MagicMock(),
+            history=mock.MagicMock(),
+            status=500,
+            message="Internal Server Error",
+        )
+
+        mock_async_request.__aenter__.return_value = failed_response
+
+        with pytest.raises(aiohttp.ClientResponseError):
+            await hook._make_api_call_with_retries_async("GET", API_URL, 
HEADERS)
+
+        failed_response.raise_for_status.assert_called_once()
+        failed_response.json.assert_not_called()
+
+    def test_make_api_call_with_retries_json_decode_error_prevention(self, 
mock_requests):
+        """
+        Test that _make_api_call_with_retries calls raise_for_status() before 
response.json()
+        to prevent JSONDecodeError when response is not valid JSON.
+        """
+        hook = SnowflakeSqlApiHook(snowflake_conn_id="test_conn")
+
+        failed_response = mock.MagicMock()
+        failed_response.status_code = 500
+        failed_response.json.side_effect = 
requests.exceptions.JSONDecodeError("Invalid JSON", "", 0)
+        failed_response.raise_for_status.side_effect = 
requests.exceptions.HTTPError(response=failed_response)
+
+        mock_requests.request.return_value = failed_response
+
+        with pytest.raises(requests.exceptions.HTTPError):
+            hook._make_api_call_with_retries("GET", API_URL, HEADERS)
+
+        failed_response.raise_for_status.assert_called_once()
+        failed_response.json.assert_not_called()

Reply via email to