apache / airflow

Apache Airflow - A platform to programmatically author, schedule, and monitor workflows
https://airflow.apache.org/
Apache License 2.0
37.09k stars 14.29k forks source link

Extra links not appearing on mapped tasks #43757

Open brentsifi opened 6 days ago

brentsifi commented 6 days ago

Apache Airflow version

2.10.2

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Extra external links are not appearing on mapped tasks.

What you think should happen instead?

While I am able to add extra external links to an existing operator (the PythonOperator in this case) and able to view them in the UI, I am not able see the extra links when using mapped tasks of the same operator.

In this screenshot, I have a non-mapped task version of a simple DAG using the PythonOperator and the extra external link button is visible. Screenshot 2024-11-05 at 1 44 32 PM

In this screenshot, I have a mapped task version of the same DAG using the PythonOperator and the extra external link is not visible. Screenshot 2024-11-05 at 1 47 27 PM

How to reproduce

Create a new directory and run astro dev init.

Create a file named my_extra_link_plugin.py with the following code and add it to the plugins folder:

from airflow.models.baseoperator import BaseOperator
from airflow.models.baseoperator import BaseOperatorLink
from airflow.models.taskinstancekey import TaskInstanceKey
from airflow.operators.python import PythonOperator
from airflow.plugins_manager import AirflowPlugin

# define the extra link
class PythonDocsLink(BaseOperatorLink):
    # name the link button in the UI
    name = "Python Docs"

    # add the button to one or more operators
    operators = [PythonOperator]

    # provide the link
    def get_link(self, operator: BaseOperator, *, ti_key: TaskInstanceKey):
        return "https://docs.python.org/3/"

# define the plugin class
class AirflowExtraLinkPlugin(AirflowPlugin):
    name = "extra_link_plugin"
    operator_extra_links = [
        PythonDocsLink(),
    ]

In the dags folder, create a file named add.py that contains the following:

from pendulum import datetime

from airflow.models.dag import DAG
from airflow.operators.python import PythonOperator

with DAG(
    dag_id="add",
    schedule=None,
    start_date=datetime(2024, 11, 3),
    catchup=False,
) as dag:
    def add_function(x: int, y: int):
        return x + y

    added_values = PythonOperator(
        task_id="add",
        python_callable=add_function,
        op_kwargs={"x": 7, "y": 10},
    )

In the dags folder, create a file named add_mapped_task.py that contains the following:

from pendulum import datetime

from airflow.models.dag import DAG
from airflow.operators.python import PythonOperator

with DAG(
    dag_id="add_with_mapped_tasks",
    schedule=None,
    start_date=datetime(2024, 11, 3),
    catchup=False,
) as dag:
    def add_function(x: int, y: int):
        return x + y

    added_values = PythonOperator.partial(
        task_id="add",
        python_callable=add_function,
        op_kwargs={"y": 10},
        # optionally, you can set a custom index to display in the UI (Airflow 2.9+)
        map_index_template="Input x={{ task.op_args[0] }}",
    ).expand(op_args=[[1], [2], [3]])

Trigger both DAGs and click on the Details tab.

Operating System

Sonoma 14.7

Versions of Apache Airflow Providers

No response

Deployment

Astronomer

Deployment details

Using Astronomer Runtime 12.2.0

Anything else?

No response

Are you willing to submit PR?

Code of Conduct

boring-cyborg[bot] commented 6 days ago

Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

eladkal commented 5 days ago

cc @bbovenzi This seems to be UI issue(?)