ashb commented on code in PR #52846:
URL: https://github.com/apache/airflow/pull/52846#discussion_r2203255998


##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -305,18 +305,29 @@ def get(self, conn_id: str) -> ConnectionResponse | 
ErrorResponse:
 
 class VariableOperations:
     __slots__ = ("client",)
+    __NO_DEFAULT_SENTINEL = object()
 
     def __init__(self, client: Client):
         self.client = client
 
-    def get(self, key: str) -> VariableResponse | ErrorResponse:
+    def get(self, key: str, default_var: Any = __NO_DEFAULT_SENTINEL) -> 
VariableResponse | ErrorResponse:
         """Get a variable from the API server."""
         try:
             resp = self.client.get(f"variables/{key}")
         except ServerResponseError as e:
             if e.response.status_code == HTTPStatus.NOT_FOUND:
+                if default_var is not self.__NO_DEFAULT_SENTINEL:
+                    log.debug(
+                        "Variable %s not found. Using default",
+                        key,
+                        key=key,
+                        detail=e.detail,
+                        status_code=e.response.status_code,
+                    )
+                    return VariableResponse(key=key, value=default_var)
                 log.error(
-                    "Variable not found",
+                    "Variable %s not found",
+                    key,

Review Comment:
   This will produce a log message of:
   
   ```
   Variable foo not found key=foo
   ```
   
   
   ```suggestion
                       "Variable not found",
   ```



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