Skip to content

Key Error in External Task Sensor when using execution_date_fn #52236

Closed

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

Activity

  1. added
    kind:bug
    needs-triage
    on Jun 25, 2025
  2. added and removed
    needs-triage
    on Jun 25, 2025
  3. added a commit that references this issue on Jun 28, 2025
    fdd246b
  4. gopidesupavan commented on Jul 1, 2025

    @gopidesupavan
    Member

    Could you please share the log ?

  5. dingo4dev commented on Jul 1, 2025

    @dingo4dev
    ContributorAuthor

    @gopidesupavan TIA, please also review my PR.

    Here is the log:

    ERROR - Task failed with exception: source="task"
    KeyError: 'logical_date'
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 867 in run
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/execution_time/task_runner.py", line 1159 in _execute_task
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 397 in wrapper
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/sensors/external_task.py", line 427 in execute
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/operator.py", line 397 in wrapper
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/sensor.py", line 227 in execute
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/sdk/bases/sensor.py", line 207 in execute
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/sensors/external_task.py", line 282 in poke
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/sensors/external_task.py", line 272 in _get_dttm_filter
    
    File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/sensors/external_task.py", line 543 in _handle_execution_date_fn
  6. added a commit that references this issue on Jul 26, 2025
    4761082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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