From a1314d01436d7a91623ba056c4eaa0ca558b91a8 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 27 Jul 2022 16:02:22 +0800 Subject: [PATCH] Don't crash if operator_extra_links is a property This makes operators that implement this as an instance property compatible for task-mapping. We still can't show those extra links (since they are only available against a concrete task), but at least they are runnable. --- airflow/models/mappedoperator.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/airflow/models/mappedoperator.py b/airflow/models/mappedoperator.py index dead62753ca3d..5ef1e2716a97c 100644 --- a/airflow/models/mappedoperator.py +++ b/airflow/models/mappedoperator.py @@ -212,6 +212,14 @@ def _expand(self, expand_input: ExpandInput, *, strict: bool) -> "MappedOperator start_date = partial_kwargs.pop("start_date") end_date = partial_kwargs.pop("end_date") + # Some operators implement extra links as a run-time property (instead + # of a class-level attribute) that is only resolvable against a concrete + # task object. There's no way to resolve them here, just leave it empty. + if isinstance(self.operator_class.operator_extra_links, collections.abc.Collection): + operator_extra_links = self.operator_class.operator_extra_links + else: + operator_extra_links = () + op = MappedOperator( operator_class=self.operator_class, expand_input=expand_input, @@ -219,7 +227,7 @@ def _expand(self, expand_input: ExpandInput, *, strict: bool) -> "MappedOperator task_id=task_id, params=params, deps=MappedOperator.deps_for(self.operator_class), - operator_extra_links=self.operator_class.operator_extra_links, + operator_extra_links=operator_extra_links, template_ext=self.operator_class.template_ext, template_fields=self.operator_class.template_fields, template_fields_renderers=self.operator_class.template_fields_renderers,