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

[GitHub] [airflow] hussein-awala opened a new pull request, #29711: fix update_mask in patch variable route

hussein-awala opened a new pull request, #29711:
URL: https://github.com/apache/airflow/pull/29711

   closes: #29702 
   
   ---
   `patch_variable` route does not allow updating the variable description. This PR updates the method and uses the same pattern used in the other routes to dynamically update all the fields which are not `non_update_fields`.


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


[GitHub] [airflow] hussein-awala commented on pull request #29711: fix update_mask in patch variable route

Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on PR #29711:
URL: https://github.com/apache/airflow/pull/29711#issuecomment-1453638791

   @dimberman Can you please review my last commit?


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


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

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
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-unsubscribe@airflow.apache.org

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


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

Posted by "dimberman (via GitHub)" <gi...@apache.org>.
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


[GitHub] [airflow] potiuk merged pull request #29711: fix update_mask in patch variable route

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk merged PR #29711:
URL: https://github.com/apache/airflow/pull/29711


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


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

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #29711:
URL: https://github.com/apache/airflow/pull/29711#issuecomment-1464222786

   @dimberman ? Is your "request changes" still valid ? I think it has been addressed but I would not want to dismiss the review without you confirming.


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


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

Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #29711:
URL: https://github.com/apache/airflow/pull/29711#issuecomment-1474993315

   Since you have not responded @dimberrman, I will simply dismiss it. 2 weeks and no response despite pinging seems to be enough. We can always have a follow-up if the "request for changes" is still not resolved.


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


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

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #29711:
URL: https://github.com/apache/airflow/pull/29711#discussion_r1130520722


##########
airflow/api_connexion/endpoints/variable_endpoint.py:
##########
@@ -103,15 +110,15 @@ 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 = extract_update_mask_data(update_mask, non_update_fields, data)
+    for key, val in data.items():
+        setattr(variable, key, val)
+    session.add(variable)
+    session.commit()

Review Comment:
   Don’t need this, the session is comitted when the function returns.



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