shahar1 commented on code in PR #77355:
URL: https://github.com/apache/airflow/pull/77355#discussion_r4668474385


##########
providers/snowflake/src/airflow/providers/snowflake/operators/snowflake.py:
##########
@@ -544,8 +548,12 @@ def get_job_status(self, external_id: JsonValue, context: 
Context) -> str:
                 raise
         if "error" in statuses:
             return "error"
+        if any(status not in {"success", "running"} for status in statuses):
+            raise RuntimeError(f"Unexpected Snowflake SQL API query statuses: 
{statuses}")
         if "running" in statuses:
             return "running"
+        if not statuses:
+            raise RuntimeError("No Snowflake SQL API query statuses returned")

Review Comment:
   **minor**: with an empty handle list, a fresh run and a reconnect now 
disagree.
   
   `ResumableJobMixin.execute_resumable` calls `submit_job` and then 
`poll_until_complete` directly on a fresh submission. It never calls 
`get_job_status` there. If `execute_query` returns `[]` (it accepts a 
`"statementHandles": []` response), `poll_on_queries` returns empty 
`error`/`running` dicts, `poll_until_complete` exits, and the task succeeds. 
`persist_job_id` also stores `[]`, because it skips only `None`. On a later 
retry, `get_resume_decision` reads that stored `[]` back and this line raises. 
The stored value is never cleared, so every further retry raises too.
   
   Could you pick one behaviour for both paths? Either reject an empty handle 
list in `submit_job` (before it is persisted), or drop this check and keep `[]` 
as "nothing to run".
   
   (Copilot's adversarial pass flagged the same gap from the fresh-submit side.)
   



##########
providers/snowflake/src/airflow/providers/snowflake/operators/snowflake.py:
##########
@@ -544,8 +548,12 @@ def get_job_status(self, external_id: JsonValue, context: 
Context) -> str:
                 raise
         if "error" in statuses:
             return "error"
+        if any(status not in {"success", "running"} for status in statuses):
+            raise RuntimeError(f"Unexpected Snowflake SQL API query statuses: 
{statuses}")

Review Comment:
   **minor**: is raising here, rather than returning a non-success status, 
intended?
   
   `get_resume_decision` already has a branch for a status that is neither 
active nor succeeded: it logs "Prior job in terminal state, resubmitting fresh" 
and resubmits. Returning the unrecognised status (or `"error"`) would take that 
branch. Raising fails the attempt instead. Because the stored handles stay in 
`task_state_store`, every later retry calls this again and fails the same way, 
so the task cannot recover without clearing state by hand.
   
   Failing rather than resubmitting can be the safer choice if a query in an 
unknown state might still be running, since resubmitting would run it twice. If 
that is the reason, a one-line comment saying so would stop someone from 
"fixing" it into a resubmit later.
   



##########
providers/snowflake/tests/unit/snowflake/operators/test_snowflake.py:
##########
@@ -981,6 +1004,28 @@ def test_get_job_status_reraises_non_404_http_error(self, 
mock_get_sql_api_query
         with pytest.raises(requests.exceptions.HTTPError):
             operator.get_job_status(["uuid1"], context={})
 
+    @pytest.mark.parametrize(
+        "statuses",
+        [
+            ["unknown"],
+            ["success", "unknown"],
+            ["running", "unknown"],
+            [],
+        ],
+    )
+    def test_get_job_status_rejects_unexpected_statuses(self, 
mock_get_sql_api_query_status, statuses):
+        operator = self._make_operator()
+        mock_get_sql_api_query_status.side_effect = [{"status": status} for 
status in statuses]
+
+        with pytest.raises(
+            RuntimeError,
+            match="Unexpected Snowflake SQL API|No Snowflake SQL API query 
statuses returned",

Review Comment:
   **nit**: with the alternation, the `[]` case would still pass if it raised 
the "Unexpected ..." error, and the other cases would pass on the empty-list 
message. Parametrizing the expected message per case pins each one to the 
branch it is meant to cover:
   
   ```python
   @pytest.mark.parametrize(
       ("statuses", "message"),
       [
           (["unknown"], "Unexpected Snowflake SQL API query statuses"),
           (["success", "unknown"], "Unexpected Snowflake SQL API query 
statuses"),
           (["running", "unknown"], "Unexpected Snowflake SQL API query 
statuses"),
           ([], "No Snowflake SQL API query statuses returned"),
       ],
   )
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to