ashb commented on code in PR #44562:
URL: https://github.com/apache/airflow/pull/44562#discussion_r1865603773
##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -157,6 +157,12 @@ def get(self, key: str) -> VariableResponse:
resp = self.client.get(f"variables/{key}")
return VariableResponse.model_validate_json(resp.read())
+ def put(self, msg):
Review Comment:
Can `msg` have a type?
##########
task_sdk/tests/api/test_client.py:
##########
@@ -133,3 +134,21 @@ def handle_request(request: httpx.Request) ->
httpx.Response:
"reason": "not_found",
}
}
+
+ def test_variable_put_success(self):
+ # Simulate a successful response from the server when putting a
variable
+ def handle_request(request: httpx.Request) -> httpx.Response:
+ if request.url.path == "/variables/test_key":
+ return httpx.Response(
+ status_code=200,
+ json={"message": "Variable successfully set"},
+ )
+ return httpx.Response(status_code=400, json={"detail": "Bad
Request"})
+
+ client = make_client(transport=httpx.MockTransport(handle_request))
+
+ msg = PutVariable(
+ key="test_key", value="test_value",
description="test_description", type="PutVariable"
Review Comment:
Should `value` always be JSON-encoded, in which case this might be more
representative.
```suggestion
key="test_key", value='"test_value"',
description="test_description", type="PutVariable"
```
##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -157,6 +157,12 @@ def get(self, key: str) -> VariableResponse:
resp = self.client.get(f"variables/{key}")
return VariableResponse.model_validate_json(resp.read())
+ def put(self, msg):
+ """Put a variable through the API server."""
Review Comment:
Nit-ish: "put" is the implementation detail, the operation is "set"
```suggestion
def set(self, msg):
"""Set an Airflow Variable via the API server."""
```
##########
task_sdk/src/airflow/sdk/api/client.py:
##########
@@ -157,6 +157,12 @@ def get(self, key: str) -> VariableResponse:
resp = self.client.get(f"variables/{key}")
return VariableResponse.model_validate_json(resp.read())
+ def put(self, msg):
+ """Put a variable through the API server."""
+ key = msg.key
+ put_resp = self.client.put(f"variables/{key}",
content=msg.model_dump_json())
+ return put_resp
Review Comment:
This should probably not have a return (raise on error only)
--
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]