Skip to content

Fix logical_date handling for using exeuction_date_fn in ExternalTaskSensor #52237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dingo4dev
Copy link
Contributor


closes #52236

@Copilot Copilot AI review requested due to automatic review settings June 25, 2025 10:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the logical date handling for the ExternalTaskSensor by updating the usage of execution_date_fn.

  • Passes logical_date as an explicit parameter to _handle_execution_date_fn rather than extracting it from the context
  • Updates the function signature and removes the redundant extraction of logical_date from the context
Comments suppressed due to low confidence (1)

providers/standard/src/airflow/providers/standard/sensors/external_task.py:532

  • Update the docstring for _handle_execution_date_fn to include and describe the new 'logical_date' parameter, ensuring the documentation accurately reflects the updated function signature.
    def _handle_execution_date_fn(self, logical_date, context) -> Any:

@dingo4dev dingo4dev force-pushed the fix/external-task-sensor branch from 33549ca to c68ed07 Compare June 25, 2025 15:21
@@ -529,7 +529,7 @@ def get_external_task_group_task_ids(self, session, dttm_filter):
dttm_filter, self.external_task_group_id, self.external_dag_id, session
)

def _handle_execution_date_fn(self, context) -> Any:
def _handle_execution_date_fn(self, logical_date, context) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method is purely for backwar compatibility and shouldn't have this breaking change here
cc: @kaxil what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bugraoz93 Thanks for review.

IMO, the backward compatibility is already handled in caller function, it is better to keep consistent and align with the 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(logical_date=logical_date, context=context)

@dingo4dev dingo4dev force-pushed the fix/external-task-sensor branch from c68ed07 to 34da955 Compare June 25, 2025 17:05
@dingo4dev dingo4dev force-pushed the fix/external-task-sensor branch from 34da955 to 3576530 Compare June 26, 2025 01:32
@dingo4dev
Copy link
Contributor Author

TBR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Key Error in External Task Sensor when using execution_date_fn
2 participants