-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Description
Apache Airflow version
2.5.1
What happened
When i made these patch requests to update description of the variable via axios
1) Trying to modify new value and description
let payload ={ key : "example_variable", value : "new_value", description: "new_Description" }
axios.patch("https://localhost:8080/api/v1/variables/example_variable" , payload ,
{
auth : {
username : "username",
password : "password"
},
headers: {
"Content-Type" : "application/json",
}
});following response received and In the airflow , Existing Variable's Description is cleared and set to None
response body : {
"description" : "new_Description",
"key": "example_variable",
"value" : "new_value"
}2) Trying to update Description with update_mask
let payload ={ key : "example_variable", value : "value", description: "new_Description" }
axios.patch("https://localhost:8080/api/v1/variables/example_variable?update_mask=description" , payload ,
{
auth : {
username : "username",
password : "password"
},
headers: {
"Content-Type" : "application/json",
}
});following response received
response body : {
"detail" : null,
"status": 400,
"detail" : "No field to update",
"type" : "https://airflow.apache.org/docs/apache-airflow/2.5.0/stable-rest-api-ref.html#section/Errors/BadRequest"
}What you think should happen instead
The filed "description" is ignored both while setting the Variable (L113) and update_mask (L107-111).
airflow/airflow/api_connexion/endpoints/variable_endpoint.py
Lines 97 to 115 in 1768872
| def patch_variable(*, variable_key: str, update_mask: UpdateMask = None) -> Response: | |
| """Update a variable by key.""" | |
| try: | |
| data = variable_schema.load(get_json_request_dict()) | |
| except ValidationError as err: | |
| raise BadRequest("Invalid Variable schema", detail=str(err.messages)) | |
| if data["key"] != variable_key: | |
| raise BadRequest("Invalid post body", detail="key from request body doesn't match uri parameter") | |
| if update_mask: | |
| if "key" in update_mask: | |
| raise BadRequest("key is a ready only field") | |
| if "value" not in update_mask: | |
| raise BadRequest("No field to update") | |
| Variable.set(data["key"], data["val"]) | |
| return variable_schema.dump(data) | |
Also in Variable setter its set to None if input doesn't contain description field
airflow/airflow/models/variable.py
Lines 156 to 165 in 1768872
| def set( | |
| key: str, | |
| value: Any, | |
| description: str | None = None, | |
| serialize_json: bool = False, | |
| session: Session = None, | |
| ): | |
| """ | |
| Sets a value for an Airflow Variable with a given Key. | |
| This operation will overwrite an existing variable. |
How to reproduce
PATCH in Airflow REST API
API call
"https://localhost:8080/api/v1/variables/example_variable?update_mask=description"
payload
{ key : "example_variable", value : "value", description: "new_Description" }
headers
"Content-Type" : "application/json"
OR
API call
"https://localhost:8080/api/v1/variables/example_variable
payload
{ key : "example_variable", value : "new_value", description: "new_Description" }
headers
"Content-Type" : "application/json"
Operating System
Ubuntu 22.04.1 LTS
Versions of Apache Airflow Providers
No response
Deployment
Official Apache Airflow Helm Chart
Deployment details
No response
Anything else
Possible Solution to update Description field can be like
airflow/airflow/api_connexion/endpoints/connection_endpoint.py
Lines 134 to 145 in 1768872
| if update_mask: | |
| update_mask = [i.strip() for i in update_mask] | |
| data_ = {} | |
| for field in update_mask: | |
| if field in data and field not in non_update_fields: | |
| data_[field] = data[field] | |
| else: | |
| raise BadRequest(detail=f"'{field}' is unknown or cannot be updated.") | |
| data = data_ | |
| for key in data: | |
| setattr(connection, key, data[key]) | |
| session.add(connection) |
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct