This is an automated email from the ASF dual-hosted git repository.
shahar1 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 371bf99e4f1 Handle malformed Snowpark container job submission
responses (#77275)
371bf99e4f1 is described below
commit 371bf99e4f1a5f4b12803bf6fc2fb560fadb323a
Author: SameerMesiah97 <[email protected]>
AuthorDate: Mon Nov 23 16:03:31 2026 +0000
Handle malformed Snowpark container job submission responses (#77275)
* Handle malformed Snowpark container job submission responses
Validate the response before extracting the job name to avoid
incidental parsing exceptions on malformed or empty responses.
Raise a descriptive RuntimeError while preserving existing
behaviour for valid responses, and extend regression test coverage.
* Remove redundant job name check and associated unit test.
---
.../snowflake/operators/snowpark_containers.py | 14 ++++++++---
.../operators/test_snowpark_containers.py | 28 ++++++++++++++--------
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git
a/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
b/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
index 3312e35019a..d5c0d640f80 100644
---
a/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
+++
b/providers/snowflake/src/airflow/providers/snowflake/operators/snowpark_containers.py
@@ -194,7 +194,16 @@ class SnowparkContainerJobOperator(BaseOperator):
def _submit_job(self) -> str:
"""Submit the job and return the name."""
response = self._run_one(self._build_sql())
- job_name = response[0].split("'")[1]
+
+ if not isinstance(response, (list, tuple)) or not response or not
isinstance(response[0], str):
+ raise RuntimeError(f"Unexpected job submission response:
{response!r}")
+
+ parts = response[0].split("'")
+ if len(parts) < 3 or not parts[1]:
+ raise RuntimeError(f"Unexpected job submission response:
{response!r}")
+
+ job_name = parts[1]
+
return job_name
def _poll_for_status(self) -> str:
@@ -260,8 +269,7 @@ class SnowparkContainerJobOperator(BaseOperator):
raise ValueError("Must provide either 'spec_text' or both 'spec'
and 'spec_stage'")
self.job_name = self._submit_job()
- if not self.job_name:
- raise RuntimeError("Job name was not returned")
+
if not self.wait_for_completion:
return self.job_name
if self.deferrable:
diff --git
a/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
b/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
index 1e344d080d0..e3abcc5e7b9 100644
---
a/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
+++
b/providers/snowflake/tests/unit/snowflake/operators/test_snowpark_containers.py
@@ -286,19 +286,27 @@ class TestSnowparkContainerJobOperator:
op.on_kill()
mock_error.assert_called_once()
+ @pytest.mark.parametrize(
+ "response",
+ [
+ pytest.param(None, id="none"),
+ pytest.param([], id="empty"),
+ pytest.param(["unexpected response"], id="unexpected_text"),
+ pytest.param([None], id="null_value"),
+ pytest.param([123], id="non_string"),
+ pytest.param(
+ ["Started Snowpark Container Services Job ''."],
+ id="empty_job_name",
+ ),
+ ],
+ )
@mock.patch(MOCK_HOOK_PATH)
- def test_submit_job_raises_on_malformed_response(self, mock_hook_cls):
- mock_hook = mock_hook_cls.return_value
- mock_hook.run.return_value = ["unexpected response"]
+ def test_submit_job_raises_on_malformed_response(self, mock_hook_cls,
response):
+ mock_hook_cls.return_value.run.return_value = response
op = _make_operator()
- with pytest.raises(IndexError):
- op._submit_job()
- @mock.patch.object(SnowparkContainerJobOperator, "_submit_job",
return_value=None)
- def test_execute_raises_when_job_name_not_returned(self, mock_submit):
- op = _make_operator()
- with pytest.raises(RuntimeError, match="Job name was not returned"):
- op.execute(context=None)
+ with pytest.raises(RuntimeError, match="Unexpected job submission
response"):
+ op._submit_job()
@mock.patch(MOCK_HOOK_PATH)
def test_execute_no_wait(self, mock_hook_cls):