Skip to content

Fix DateTimeSensorAsync crash on templated target_time with start_from_trigger - #70469

Draft
burakcoleman wants to merge 1 commit into
apache:mainfrom
burakcoleman:fix-datetime-sensor-async-templated-target-time
Draft

Fix DateTimeSensorAsync crash on templated target_time with start_from_trigger#70469
burakcoleman wants to merge 1 commit into
apache:mainfrom
burakcoleman:fix-datetime-sensor-async-templated-target-time

Conversation

@burakcoleman

@burakcoleman burakcoleman commented Jul 26, 2026

Copy link
Copy Markdown

DateTimeSensorAsync.__init__ computes start_trigger_args.trigger_kwargs["moment"] by calling
timezone.parse(self.target_time) at Dag-parse time, before Jinja templating has run. target_time
is a documented template field (e.g. "{{ data_interval_end.tomorrow().replace(hour=1) }}"), so a
templated value raises a raw pendulum.parsing.exceptions.ParserError there, crashing parsing of the
entire Dag file, not just the one task.

This can't be fixed by moving the parse into execute(): when start_from_trigger=True, the scheduler
defers the task straight from TaskInstance.defer_task() using the pre-computed self.task.start_trigger_args
execute() never runs for this path. So the value genuinely has to be resolved in __init__, the same
constraint TimeSensor hit in #69610.

Fix: catch the parse failure and raise a clear ValueError explaining that start_from_trigger=True
requires a static target_time, instead of letting the raw ParserError propagate and take down the
whole Dag file. Static/ISO target_time values are unaffected and keep working exactly as before.

Added tests covering both the static-time (still works) and templated-time (now raises a clear,
task-scoped error instead of crashing Dag parsing) cases.

closes: #70284
Related: #69610

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code

…m_trigger

DateTimeSensorAsync.__init__ computes start_trigger_args.trigger_kwargs["moment"]
by parsing target_time at Dag-parse time, before Jinja templating runs. Since
target_time is a documented template field, a templated value (e.g.
"{{ data_interval_end.tomorrow().replace(hour=1) }}") raises a raw
pendulum ParserError there, crashing parsing of the entire Dag file.

The parse can't be deferred to execute(): when start_from_trigger=True the
scheduler defers straight from TaskInstance.defer_task() using the
pre-computed start_trigger_args, so execute() never runs. That's the same
constraint TimeSensor hit in apache#69610, so this applies the same remedy: raise
a clear ValueError instead of letting the parser error propagate.

Static/ISO target_time values are unaffected and keep working as before.

closes: apache#70284
Related: apache#69610

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@boring-cyborg

boring-cyborg Bot commented Jul 26, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our prek-hooks will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example Dag that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@raphaelauv

Copy link
Copy Markdown
Contributor

same than #70310 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DateTimeSensorAsync crashes Dag parsing with templated target_time + start_from_trigger=True

2 participants