hwang-cadent commented on code in PR #56973:
URL: https://github.com/apache/airflow/pull/56973#discussion_r2491531684


##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -79,16 +80,31 @@ def get_link(self, operator: BaseOperator, *, ti_key: 
TaskInstanceKey) -> str:
         if TYPE_CHECKING:
             assert isinstance(operator, TriggerDagRunOperator)
 
-        trigger_dag_id = operator.trigger_dag_id
-        if not AIRFLOW_V_3_0_PLUS:
-            from airflow.models.renderedtifields import 
RenderedTaskInstanceFields
-
-            if template_fields := 
RenderedTaskInstanceFields.get_templated_fields(ti_key):
-                trigger_dag_id: str = template_fields.get("trigger_dag_id", 
operator.trigger_dag_id)  # type: ignore[no-redef]
+        # Try to get the resolved dag_id from XCom first (for dynamic dag_ids)
+        trigger_dag_id = None
+        try:
+            trigger_dag_id = XCom.get_value(ti_key=ti_key, key=XCOM_DAG_ID)
+        except (ImportError, AttributeError):
+            # Fallback for test environments or when supervisor comms is not 
available
+            pass

Review Comment:
   Thanks for the review! Good catch! I've addressed this by:
   
   1. **Removed test-specific error handling**: Removed the `try-except` blocks 
around `XCom.get_value()` calls in `TriggerDagRunLink.get_link()`
   
   2. **Updated tests to use proper mocking**: Added 
`@mock.patch("airflow.providers.standard.operators.trigger_dagrun.XCom.get_value")`
 decorators to all tests that call `get_link()`, including:
      - `test_extra_operator_link` (both AF2 and AF3)
      - `test_extra_operator_link_with_dynamic_dag_id` (both AF2 and AF3)
   
   3. **Verified all tests pass**: All 10 Airflow 3.x tests pass with proper 
mocking
   
   The production code is now cleaner without test-specific workarounds, and 
tests properly mock the XCom behavior.



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