uranusjr commented on code in PR #23510:
URL: https://github.com/apache/airflow/pull/23510#discussion_r884236575


##########
airflow/security/permissions.py:
##########
@@ -66,14 +66,15 @@
 DAG_ACTIONS = {ACTION_CAN_READ, ACTION_CAN_EDIT, ACTION_CAN_DELETE}
 
 
-def resource_name_for_dag(dag_id):
+def resource_name_for_dag(dag_id, root_dag_id=None):
     """Returns the resource name for a DAG id."""
     if dag_id == RESOURCE_DAG:
         return dag_id
 
     if dag_id.startswith(RESOURCE_DAG_PREFIX):
         return dag_id
 
-    # To account for SubDags
-    root_dag_id = dag_id.split(".")[0]
-    return f"{RESOURCE_DAG_PREFIX}{root_dag_id}"
+    if root_dag_id:
+        # To account for SubDags
+        return f"{RESOURCE_DAG_PREFIX}{root_dag_id}"
+    return f"{RESOURCE_DAG_PREFIX}{dag_id}"

Review Comment:
   Hmm, actually I think we can remove the entire if-else clause if we simply 
always call this with `root_dag_id: str`?
   
   ```python
   def resource_name_for_dag(root_dag_id: str) -> str:
       """Returns the resource name for a DAG id.
   
       Note that since a sub-DAG should follow the permission of its
       parent DAG, you should pass ``dag.root_dag_id`` to this function,
       not ``dag.dag_id``.
       """
       if root_dag_id == RESOURCE_DAG:
           return root_dag_id
       if root_dag_id.startswith(RESOURCE_DAG_PREFIX):
           return root_dag_id
       return f"{RESOURCE_DAG_PREFIX}{root_dag_id}"
   
   
   # Use it like this...
   dag_resource_name = resource_name_for_dag(root_dag_id)
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to