seanghaeli commented on code in PR #77026:
URL: https://github.com/apache/airflow/pull/77026#discussion_r4651542512


##########
airflow-core/src/airflow/dag_processing/collection.py:
##########
@@ -1475,7 +1481,9 @@ def add_asset_trigger_references(
 
             asset_model = assets[name_uri]
             trigger_hash_from_asset_model: set[int] = {
-                BaseEventTrigger.hash(trigger.classpath, trigger.kwargs) for 
trigger in asset_model.triggers
+                BaseEventTrigger.hash(trigger.classpath, trigger.kwargs)
+                for trigger in asset_model.triggers
+                if not multi_team or trigger.team_name == team_name

Review Comment:
   My agent flagged this one: the conflict with #76982 is here, and main's side 
of it is a loop over `asset_model.watchers` with no team filter. Resolved that 
way, #76992 comes back. In Breeze with two team bundles and a triggerer per 
team, the second team to parse never got its own trigger for the shared asset, 
and the two teams renamed the one watcher back and forth on every parse (22 
"Changing asset watcher name" warnings in three minutes). With `if multi_team 
and watcher.trigger.team_name != team_name: continue` at the top of that loop, 
each team got its own trigger and watcher name, run by its own triggerer, with 
no renames.



##########
airflow-core/src/airflow/dag_processing/collection.py:
##########
@@ -1456,6 +1456,12 @@ def add_asset_trigger_references(
         # Optimization: if no asset collected, skip fetching active assets
         active_assets = _find_active_assets(self.assets, session=session) if 
self.assets else {}
 
+        # With multi-team enabled, a parse only manages its own team's 
watchers:
+        # diffing, reuse and removal are all scoped to ``team_name``, so two 
teams
+        # declaring the identical watcher each get their own trigger and each
+        # team's triggerer runs its own copy (#76992).

Review Comment:
   With a copy per team, both copies fire on every change, and by default a 
watcher's event queues every Dag on the asset whatever its team, so each team's 
Dag now runs twice per change. In Breeze, two changes to the watched file gave 
both teams' Dags four runs each, one per copy per change (two each on main). Is 
that intended?



##########
airflow-core/src/airflow/dag_processing/collection.py:
##########
@@ -1550,8 +1557,12 @@ def add_asset_trigger_references(
                     watcher
                     for watcher in asset_model.watchers
                     if watcher.trigger is not None
-                    and BaseEventTrigger.hash(watcher.trigger.classpath, 
watcher.trigger.kwargs)
-                    not in trigger_hashes
+                    and (
+                        # Another team's watcher is never ours to remove
+                        (multi_team and watcher.trigger.team_name != team_name)

Review Comment:
   This keeps another team's watcher, and a teamless one, whatever this parse 
finds. So if team A stops scheduling on the asset while team B still does, A's 
watcher and trigger stay on it: in Breeze, A's triggerer kept running it and 
B's Dag kept getting its events. And a watcher from before multi-team was 
turned on stays next to the team's new copy, and is still there after the Dag 
drops it, so its trigger never gets cleaned up (the description says it does; 
that one I checked by calling `add_asset_trigger_references` directly). Could 
the removal also drop a teamless watcher, and another team's once that team no 
longer schedules on the asset, with a test for each?



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