dstandish commented on code in PR #44456:
URL: https://github.com/apache/airflow/pull/44456#discussion_r1876169526


##########
airflow/dag_processing/collection.py:
##########
@@ -435,14 +456,20 @@ def add_asset_trigger_references(
         refs_to_add: dict[tuple[str, str], set[str]] = {}
         refs_to_remove: dict[tuple[str, str], set[str]] = {}
         triggers: dict[str, BaseTrigger] = {}
+
+        # Optimization: if no asset collected, skip fetching active assets
+        active_assets = _find_active_assets(self.assets.keys(), 
session=session) if self.assets else {}
+
         for name_uri, asset in self.assets.items():
-            asset_model = assets[name_uri]
+            # If the asset belong to a DAG not active or paused, consider 
there is no watcher associated to it
+            asset_watchers = asset.watchers if name_uri in active_assets else 
[]
             trigger_repr_to_trigger_dict: dict[str, BaseTrigger] = {
-                repr(trigger): trigger for trigger in asset.watchers
+                repr(trigger): trigger for trigger in asset_watchers

Review Comment:
   is there not like an ID or something?
   
   let me give you an example
   
   i have seen that TI repr may have non-pk attrs in there. so it's possible 
you could get the same TI in the dict 2 times if its state changed.
   
   also, it's possible that someone maybe could change the repr to a non-pk 
attr like `<MyObject(name="blah")>` when multiple distinct objects could have 
the same name and then unwittingly introduce a problem.  



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