Fix scheduler crash on log_filename_template with null logical_date#68149
Open
Vamsi-klu wants to merge 3 commits into
Open
Fix scheduler crash on log_filename_template with null logical_date#68149Vamsi-klu wants to merge 3 commits into
Vamsi-klu wants to merge 3 commits into
Conversation
Vamsi-klu
pushed a commit
to Vamsi-klu/airflow
that referenced
this pull request
Jun 7, 2026
The check-newsfragment-pr-number CI check requires the newsfragment file to be named after the PR number, not the issue number. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
This fixes a scheduler crash when rendering cc @uranusjr @jscheffl — would appreciate a review when you have time (no code owner is registered for |
The check-newsfragment-pr-number CI check requires the newsfragment file to be named after the PR number, not the issue number.
65f69a7 to
ce887a5
Compare
The check-newsfragments-are-valid hook requires non-significant newsfragments to be a single line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Make the scheduler-side log filename renderer (
log_filename_template_rendererinairflow-core/src/airflow/utils/helpers.py) tolerate a nulllogical_date:ti.logical_date or ti.run_after(run_afteris non-nullable onDagRun), so the renderer never dereferencesNone.tsandts_nodashto Jinja templates, so templates can reference a stable timestamp without touchingti.logical_datedirectly.run_id-based template instead of propagating the exception.Why
Since AIP-83,
DagRun.logical_date(and thereforeti.logical_date) isNonefor asset-triggered / partitioned runs (#68075). When a customlog_filename_templatereferencesti.logical_date— e.g. the reportedts_nodash | default(ti.logical_date.strftime("%Y%m%dT%H%M%S"))— rendering raises'None' has no attribute 'strftime'. This happens inside_enqueue_task_instances_with_queued_state, in the scheduler critical section, so the whole scheduler crashes rather than just one task failing. Jinja'sdefault()evaluates its argument eagerly, so exposing variables alone cannot rescue a template that callsti.logical_date.strftime(...)directly — hence the additional fallback path.The
ti.logical_date or ti.run_afterderivation matches the read side,FileTaskHandler._render_filename(airflow-core/src/airflow/utils/log/file_task_handler.py, which usesdag_run.logical_date or dag_run.run_after), so the write and read paths resolve to the same log path.Impact
logical_date.logical_dateruns,logical_date/ts/ts_nodashnow resolve torun_afterinstead of erroring.run_id-based filename (with a logged warning) rather than aborting scheduling — log paths for such tasks may differ from the custom template until the template is fixed.run_idortsoverti.logical_dateinlog_filename_template.airflow-core/newsfragments/68149.bugfix.rstdocumenting the user-facing fix.Testing
Adds
TestLogFilenameTemplateRendererinairflow-core/tests/unit/utils/test_helpers.py(db tests; the template is injected via theAIRFLOW__LOGGING__LOG_FILENAME_TEMPLATEenv var because the default template contains%, which configparser interpolation cannot round-trip):test_jinja_ts_is_none_safe(parametrized overlogical_dateset andNone): a{{ ts }}template renders to therun_after-derived timestamp without crashing.test_fstring_logical_date_none_uses_run_after: an f-string{logical_date}template withlogical_date=Nonefalls back torun_after.test_broken_template_does_not_crash_scheduler: the exact failing template from ti.logical_date is not populated on scheduler ti logging #68075 (callingti.logical_date.strftime(...)viadefault()) withlogical_date=Nonemust not raise; the renderer falls back to the default and the result contains therun_id.test_write_path_matches_read_path(parametrized over Jinja and f-string templates,logical_dateset andNone): asserts the write-side renderer andFileTaskHandler._render_filenameproduce identical paths.closes: #68075
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines