aaron-y-chen commented on code in PR #76493:
URL: https://github.com/apache/airflow/pull/76493#discussion_r4689225015


##########
airflow-core/src/airflow/models/dag.py:
##########
@@ -896,17 +898,34 @@ def calculate_dagrun_date_fields(
         )
 
     @staticmethod
-    @cached(_team_name_cache, key=lambda dag_id, **_: dag_id, 
lock=_team_name_cache_lock)
-    @provide_session
-    def get_team_name(dag_id: str, *, session: Session = NEW_SESSION) -> str | 
None:
-        """Return the team name associated to a Dag or None if it is not owned 
by a specific team."""
-        stmt = (
+    def _build_team_name_query(dag_id: str) -> Select[tuple[str]]:
+        return (
             select(Team.name)
             .join(DagBundleModel.teams)
             .join(DagModel, DagModel.bundle_name == DagBundleModel.name)
             .where(DagModel.dag_id == dag_id)
         )
-        return session.scalar(stmt)
+
+    @staticmethod
+    @cached(_team_name_cache, key=lambda dag_id, **_: dag_id, 
lock=_team_name_cache_lock)
+    @provide_session
+    def get_team_name(dag_id: str, *, session: Session = NEW_SESSION) -> str | 
None:
+        """Return the team name associated to a Dag or None if it is not owned 
by a specific team."""
+        return session.scalar(DagModel._build_team_name_query(dag_id))
+
+    @staticmethod
+    async def get_team_name_async(dag_id: str, *, session: AsyncSession) -> 
str | None:
+        """Return the team name of a Dag like :meth:`get_team_name`, sharing 
its cache."""
+        # The lock is a threading.Lock: held across the await, it would 
deadlock the next coroutine
+        # on this event loop that looks up a team name.
+        with _team_name_cache_lock:

Review Comment:
   Good catch, use a helper can prevent a change to one silently breaking the 
other.
   
   Let me fix it.



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