iRAFEEK opened a new pull request, #70343:
URL: https://github.com/apache/airflow/pull/70343

   Closes #55432
   
   ## Problem
   
   `BaseOperatorLink.get_link()` was an `@abstractmethod`, forcing every
   subclass to implement it even when the link URL is a constant (e.g.,
   a documentation link). This meant operators with static links still had
   to push to XCom during `execute()` and read from the metadata database
   on every task run, adding unnecessary overhead.
   
   ## Solution
   
   This PR introduces an optional `static_url` property on
   `BaseOperatorLink`:
   
   - `static_url` defaults to `None` (no behavior change for existing 
subclasses)
   - `get_link()` is no longer `@abstractmethod`; its default implementation
     returns `static_url` if set, otherwise raises `NotImplementedError`
     with a helpful message guiding the developer to override one or the other
   - Subclasses with a constant URL can now override `static_url` instead
     of `get_link()`, with zero XCom involvement
   
   ## Backward Compatibility
   
   Fully backward-compatible. All existing subclasses that implement
   `get_link()` continue to work without any changes.
   
   ## Example
   
   ```python
   class MyDocsLink(BaseOperatorLink):
       name = "Documentation"
       operators = [MyOperator]
   
       @property
       def static_url(self) -> str:
           return "https://myoperator.readthedocs.io";
       # No get_link() needed — no XCom push during execute()
   ```
   
   ## Tests
   
   Added `task-sdk/tests/task_sdk/bases/test_operatorlink.py` covering:
   - `static_url` defaults to `None`
   - Subclass using `static_url` returns correct URL from `get_link()`
   - Subclass overriding `get_link()` directly still works (existing behavior)
   - Subclass implementing neither raises `NotImplementedError` with a clear 
message
   - `name` remains abstract


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