You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "SubhamSinghal (via GitHub)" <gi...@apache.org> on 2024/04/12 11:41:30 UTC

[PR] Adds job_id as path param in update permission [airflow]

SubhamSinghal opened a new pull request, #38962:
URL: https://github.com/apache/airflow/pull/38962

   job_id needs to be passed as path param in update job permission api.
   api link: https://docs.databricks.com/api/workspace/jobs/updatepermissions


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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            self.log.error("Could not update permission %s", e)

Review Comment:
   IMO , if user is passing ACL and is expecting the permissions to be updated, then we should reraise the exception, otherwise the task will be marked as success without the expected outcome of permissions being updated too. WDYT?



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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            print("Could not update permission ", e)

Review Comment:
   I have added logs instead of rerasing any exception, so that it does not disrupt original flow.



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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            self.log.error("Could not update permission %s", e)

Review Comment:
   Removed try catch block. This will throw error if there is an error in updating job permission.



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


Re: [PR] Adds job_id as path param in update permission [airflow]

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

   @pankajkoti not till now. I am trying to understand how to test this locally. 
   I will add try catch in this function so that it will not disrupt original flow


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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            self.log.error("Could not update permission %s", e)

Review Comment:
   ```suggestion
               self.log.error("Could not update permission %s", e)
               raise
   ```
   



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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


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


Re: [PR] Adds job_id as path param in update permission [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #38962:
URL: https://github.com/apache/airflow/pull/38962#discussion_r1562724552


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            print("Could not update permission ", e)

Review Comment:
   I guess reraise makes more sense in this case



##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            print("Could not update permission ", e)

Review Comment:
   I think we probably should use logging instead of print or reraise?



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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            self.log.error("Could not update permission %s", e)

Review Comment:
   ```suggestion
               self.log.error("Could not update permission %s", e)
               reraise
   ```
   



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


Re: [PR] Adds job_id as path param in update permission [airflow]

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

   > @pankajkoti not till now. I am trying to understand how to test this locally. I will add try catch in this function so that it will not disrupt original flow
   
   @SubhamSinghal Are you using not using [Breeze](https://github.com/apache/airflow/blob/main/dev/breeze/doc/README.rst) for local development? It makes life a lot easier for developing and testing. 


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


Re: [PR] Adds job_id as path param in update permission [airflow]

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

   Tested. Code is working fine.


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


Re: [PR] Adds job_id as path param in update permission [airflow]

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


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            self.log.error("Could not update permission %s", e)

Review Comment:
   Removed try catch block. This will throw error if there is an error in updating job permission. Let me know if this is fine.



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


Re: [PR] Adds job_id as path param in update permission [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #38962:
URL: https://github.com/apache/airflow/pull/38962#discussion_r1564461104


##########
airflow/providers/databricks/hooks/databricks.py:
##########
@@ -656,14 +655,20 @@ def get_repo_by_path(self, path: str) -> str | None:
 
         return None
 
-    def update_job_permission(self, json: dict[str, Any]) -> dict:
+    def update_job_permission(self, job_id: int, json: dict[str, Any]) -> dict:
         """
         Update databricks job permission.
 
+        :param job_id: job id
         :param json: payload
         :return: json containing permission specification
         """
-        return self._do_api_call(UPDATE_PERMISSION_ENDPOINT, json)
+        response = {}
+        try:
+            response = self._do_api_call(("PATCH", f"api/2.0/permissions/jobs/{job_id}"), json)
+        except Exception as e:
+            self.log.error("Could not update permission %s", e)

Review Comment:
   Agree with @pankajkoti  👍 
   



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