You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "dimberman (via GitHub)" <gi...@apache.org> on 2023/02/23 19:55:01 UTC

[GitHub] [airflow] dimberman commented on a diff in pull request #29711: fix update_mask in patch variable route

dimberman commented on code in PR #29711:
URL: https://github.com/apache/airflow/pull/29711#discussion_r1116182339


##########
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)
+        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_

Review Comment:
   This seems like a lot of nesting. Can you break this out into a separate function?



-- 
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-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org