sujitha-saranam opened a new pull request, #55257:
URL: https://github.com/apache/airflow/pull/55257

   #### Feature
   
   Add support for defining extra links directly within TaskFlow DAGs.
   
   Currently, extra links require creating a custom operator and defining a 
BaseOperatorLink. This is too heavy for one-off tasks where authors just want 
to expose a useful URL (e.g., an API endpoint, a dashboard).
   
   With this feature, DAG authors can set extra links in @task functions, and 
they will behave like operator extra links in the UI.
   
   #### Changes Made
   - Added support for storing extra links directly in task context 
(context["extra_links"]).
   - Implemented logic to persist extra links into XCom (extra_link:<name> 
keys).
   - Updated template context to include extra_links dictionary.
   - Loaded extra links from XCom back into task context for UI/API visibility.
   - Added test cases for the new feature.
   
   #### Tests Added
   - `test_parameterized_extra_links_dag`
   - `test_context_based_extra_links_dag`
   
   #### Sample dag files and screeshots
   
   - DAG demonstrating extra links added via context dictionary.
   
   ``` python
   from airflow.sdk import get_current_context, dag, task
   from datetime import datetime, timedelta
   import requests
   
   
   @dag(
       start_date=datetime.now() - timedelta(days=1),
       schedule=None,
       catchup=False,
       tags=["extra_links_example"],
   )
   def example_extra_links_dag():
       @task
       def get_api_resource():
           context = get_current_context()
           rsp = requests.get("https://www.google.com";, timeout=10)
           context.setdefault("extra_links", {})
           context["extra_links"]["Google"] = "https://www.google.com";
           return {"status_code": rsp.status_code}
       get_api_resource()
   
   
   example_extra_links_dag()
   ```
   <img width="1706" height="887" alt="image" 
src="https://github.com/user-attachments/assets/a576c158-4f12-4a0a-8e4b-57174c2fa7db";
 />
   
   <img width="1853" height="862" alt="image" 
src="https://github.com/user-attachments/assets/7f5f3dc9-6192-4ceb-8d71-e16bdbffc698";
 />
   
   
   - Support adding extra links to DAG tasks via parameters
   
   ``` python
   from airflow.sdk import get_current_context, dag, task
   from datetime import datetime, timedelta
   import requests
   
   
   @dag(
       start_date=datetime.now() - timedelta(days=1),
       schedule=None,
       catchup=False,
       tags=["extra_links_dag"],
   )
   def extra_links_dag():
       @task
       def get_api_resource(extra_links: dict[str, str]):
           rsp = requests.get("https://www.google.com";, timeout=10)
           extra_links["Google"] = "https://www.google.com";
           return {"status_code": rsp.status_code}
   
       get_api_resource(extra_links={})
   
   extra_links_dag()
   ```
   <img width="1721" height="896" alt="image" 
src="https://github.com/user-attachments/assets/0f70a6b3-d7fd-445c-b686-bcdccfa096f1";
 />
   
   
   <img width="1853" height="862" alt="image" 
src="https://github.com/user-attachments/assets/63e1dfaa-0b38-456d-b6ed-5634cc0f5943";
 />
   
   closes: #54527
   related: #54527


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