henry3260 commented on code in PR #74382:
URL: https://github.com/apache/airflow/pull/74382#discussion_r4399399758


##########
airflow-ctl/src/airflowctl/ctl/cli_config.py:
##########
@@ -66,6 +66,25 @@ def command(*args, **kwargs):
     return command
 
 
+_WRITE_METHODS = frozenset({"POST", "PUT", "PATCH", "DELETE"})
+
+
+def _warn_if_write_may_have_applied(error: httpx.HTTPError) -> None:
+    """Warn that a failed write is not retried because the server may already 
have applied it."""
+    if isinstance(error, httpx.HTTPStatusError) and error.response.status_code 
< 500:
+        return
+    try:
+        method = error.request.method

Review Comment:
   Could we extract this into a helper in client.py? The same four lines are in
   `_should_retry_api_request `(client.py:337-341), and the reason for catching 
`RuntimeError` -- httpx leaves .request unset when it has no Request to attach 
is not obvious enough to re-derive at a second call site.
   
   Returning None when the method is unknown keeps both call sites to one line,
   since None is in neither set:
   
       def _request_method(error: httpx.HTTPError) -> str | None:
           """httpx leaves ``.request`` unset when it has no Request to attach, 
and reading it then raises."""
           try:
               return error.request.method
           except RuntimeError:
               return None



-- 
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