Skip to content

Key Error in External Task Sensor when using execution_date_fn #52236

@dingo4dev

Description

@dingo4dev

Apache Airflow Provider(s)

standard

Versions of Apache Airflow Providers

1.3.0

Apache Airflow version

3.0.2

Operating System

Debian GNU/Linux 12 (bookworm)

Deployment

Official Apache Airflow Helm Chart

Deployment details

No response

What happened

There is a key error of logical_date when using execution_date_fn in ExternalTaskSensor

def _handle_execution_date_fn(self, context) -> Any:
"""
Handle backward compatibility.
This function is to handle backwards compatibility with how this operator was
previously where it only passes the logical date, but also allow for the newer
implementation to pass all context variables as keyword arguments, to allow
for more sophisticated returns of dates to return.
"""
from airflow.utils.operator_helpers import make_kwargs_callable
# Remove "logical_date" because it is already a mandatory positional argument
logical_date = context["logical_date"]
kwargs = {k: v for k, v in context.items() if k not in {"execution_date", "logical_date"}}

What you think should happen instead

Should pass the logical_date args from caller

def _get_dttm_filter(self, context):
logical_date = context.get("logical_date")
if AIRFLOW_V_3_0_PLUS:
if logical_date is None:
dag_run = context.get("dag_run")
if TYPE_CHECKING:
assert dag_run
logical_date = dag_run.run_after
if self.execution_delta:
dttm = logical_date - self.execution_delta
elif self.execution_date_fn:
dttm = self._handle_execution_date_fn(context=context)

How to reproduce

Use execution_date_fn in ExternalTaskSensor

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions