This is an automated email from the ASF dual-hosted git repository.

uranusjr pushed a commit to branch v2-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v2-10-test by this push:
     new 0af9b9a500a Emit warning for deprecated get_link signature (#46448)
0af9b9a500a is described below

commit 0af9b9a500adc2c1ae600b576325bda86919ef9c
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Wed Feb 19 18:42:05 2025 +0800

    Emit warning for deprecated get_link signature (#46448)
---
 airflow/models/abstractoperator.py                        | 12 +++++++++++-
 tests/api_connexion/endpoints/test_extra_link_endpoint.py | 11 ++++-------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/airflow/models/abstractoperator.py 
b/airflow/models/abstractoperator.py
index ec3d1f5309a..00261ee9565 100644
--- a/airflow/models/abstractoperator.py
+++ b/airflow/models/abstractoperator.py
@@ -19,6 +19,7 @@ from __future__ import annotations
 
 import datetime
 import inspect
+import warnings
 from abc import abstractproperty
 from functools import cached_property
 from typing import TYPE_CHECKING, Any, Callable, ClassVar, Collection, 
Iterable, Iterator, Sequence
@@ -27,7 +28,7 @@ import methodtools
 from sqlalchemy import select
 
 from airflow.configuration import conf
-from airflow.exceptions import AirflowException
+from airflow.exceptions import AirflowException, RemovedInAirflow3Warning
 from airflow.models.expandinput import NotFullyPopulated
 from airflow.models.taskmixin import DAGNode, DependencyMixin
 from airflow.template.templater import Templater
@@ -540,6 +541,15 @@ class AbstractOperator(Templater, DAGNode):
         old_signature = all(name != "ti_key" for name, p in parameters.items() 
if p.kind != p.VAR_KEYWORD)
 
         if old_signature:
+            warnings.warn(
+                f"Operator link {link_name!r} uses the deprecated get_link() "
+                "signature that takes an execution date. Change the signature "
+                "to accept 'self, operator, ti_key' instead. See documentation 
"
+                " *Define an operator extra link* to find what information is "
+                "available in 'ti_key'.",
+                category=RemovedInAirflow3Warning,
+                stacklevel=1,
+            )
             return link.get_link(self.unmap(None), ti.dag_run.logical_date)  # 
type: ignore[misc]
         return link.get_link(self.unmap(None), ti_key=ti.key)
 
diff --git a/tests/api_connexion/endpoints/test_extra_link_endpoint.py 
b/tests/api_connexion/endpoints/test_extra_link_endpoint.py
index cafdc8979ec..160933771a0 100644
--- a/tests/api_connexion/endpoints/test_extra_link_endpoint.py
+++ b/tests/api_connexion/endpoints/test_extra_link_endpoint.py
@@ -207,17 +207,17 @@ class TestGetExtraLinks(BaseGetExtraLinks):
         class GoogleLink(BaseOperatorLink):
             name = "Google"
 
-            def get_link(self, operator, dttm):
+            def get_link(self, operator, *, ti_key):
                 return "https://www.google.com";
 
         class S3LogLink(BaseOperatorLink):
             name = "S3"
             operators = [CustomOperator]
 
-            def get_link(self, operator, dttm):
+            def get_link(self, operator, *, ti_key):
                 return (
                     f"https://s3.amazonaws.com/airflow-logs/{operator.dag_id}/";
-                    f"{operator.task_id}/{quote_plus(dttm.isoformat())}"
+                    f"{operator.task_id}/{quote_plus(ti_key.run_id)}"
                 )
 
         class AirflowTestPlugin(AirflowPlugin):
@@ -239,10 +239,7 @@ class TestGetExtraLinks(BaseGetExtraLinks):
             assert {
                 "Google Custom": None,
                 "Google": "https://www.google.com";,
-                "S3": (
-                    "https://s3.amazonaws.com/airflow-logs/";
-                    
"TEST_DAG_ID/TEST_SINGLE_LINK/2020-01-01T00%3A00%3A00%2B00%3A00"
-                ),
+                "S3": 
"https://s3.amazonaws.com/airflow-logs/TEST_DAG_ID/TEST_SINGLE_LINK/TEST_DAG_RUN_ID";,
             } == response.json
 
 

Reply via email to