uranusjr commented on code in PR #29711: URL: https://github.com/apache/airflow/pull/29711#discussion_r1115284506
########## airflow/api_connexion/endpoints/variable_endpoint.py: ########## @@ -103,15 +109,22 @@ def patch_variable(*, variable_key: str, update_mask: UpdateMask = None) -> Resp if data["key"] != variable_key: raise BadRequest("Invalid post body", detail="key from request body doesn't match uri parameter") - + non_update_fields = ["key"] + variable = session.query(Variable).filter_by(key=variable_key).first() 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) + 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_ Review Comment: ```suggestion data_ = {} for field in update_mask: field = field.strip() 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_ ``` ########## airflow/api_connexion/endpoints/variable_endpoint.py: ########## @@ -103,15 +109,22 @@ def patch_variable(*, variable_key: str, update_mask: UpdateMask = None) -> Resp if data["key"] != variable_key: raise BadRequest("Invalid post body", detail="key from request body doesn't match uri parameter") - + non_update_fields = ["key"] + variable = session.query(Variable).filter_by(key=variable_key).first() 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) + 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(variable, key, data[key]) Review Comment: ```suggestion for key, val in data.items(): setattr(variable, key, val) ``` -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org