Skip to content

Fix CronMixin in task-sdk not resolving cron presets before validation#66102

Open
shashbha14 wants to merge 8 commits into
apache:mainfrom
shashbha14:fix/cron-mixin-presets-66101
Open

Fix CronMixin in task-sdk not resolving cron presets before validation#66102
shashbha14 wants to merge 8 commits into
apache:mainfrom
shashbha14:fix/cron-mixin-presets-66101

Conversation

@shashbha14
Copy link
Copy Markdown
Contributor

@shashbha14 shashbha14 commented Apr 29, 2026

Closes #66101
The problem was Cron presets like '@quarterly' ceased functioning in Airflow 3.2.1.Upon moving 'CronMixin' to the task-sdk module, the process to resolve the preset values disappeared. With the introduction of the @attrs.define
decorator, the preset value is passed straight to 'croniter', where @quarterly isn't recognised, resulting in 'CroniterBadCronError', raised as 'AirflowTimetableInvalid'.

Fix-
Included a 'CRON_PRESETS' dictionary in the _cron.py module of the SDK and added an 'attrs_post_init' function that would convert the preset name to its corresponding cron expression before performing any further
validation or scheduling operations.

I used Claude (claude.ai) as an AI assistant for parts of this implementation.

@shashbha14 shashbha14 marked this pull request as ready for review April 30, 2026 05:52
Comment thread task-sdk/src/airflow/sdk/definitions/timetables/_cron.py
Comment thread task-sdk/src/airflow/sdk/definitions/timetables/_cron.py
Comment thread task-sdk/tests/task_sdk/definitions/test_timetables.py
Comment thread task-sdk/tests/task_sdk/definitions/test_timetables.py
Copy link
Copy Markdown
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

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

Left some minor comments, but lgtm otherwise

@kaxil kaxil added this to the Airflow 3.2.2 milestone May 1, 2026
@kaxil kaxil added the backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch label May 1, 2026
@potiuk
Copy link
Copy Markdown
Member

potiuk commented May 5, 2026

@shashbha14 — There are 4 unresolved review thread(s) on this PR from @kaxil. Could you either push a fix or reply in each thread explaining why the feedback doesn't apply? Once you believe the feedback is addressed, mark the thread as resolved so the reviewer isn't re-pinged needlessly. Thanks!


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

@shashbha14
Copy link
Copy Markdown
Contributor Author

@kaxil the only failing check is the MongoDB provider compatibility test ,all 33 errors are 'Timeout >60.0s' from testcontainers failing to pull the MongoDB Docker image. This has failed identically on 3 consecutive runs and
is unrelated to this PR's changes which only touch task-sdk timetables. Could you please trigger a re-run or override this flaky check?

Comment on lines +30 to +41
# Mirrors airflow.utils.dates.cron_presets in airflow-core (the SDK cannot
# import core). If a preset is added or changed here it must also be updated
# there, and vice-versa.
CRON_PRESETS: dict[str, str] = {
"@hourly": "0 * * * *",
"@daily": "0 0 * * *",
"@weekly": "0 0 * * 0",
"@monthly": "0 0 1 * *",
"@quarterly": "0 0 1 */3 *",
"@yearly": "0 0 1 1 *",
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs a way to keep things in sync automatically. A pre-commit hook maybe.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Instead of a pre-commit hook, made airflow-core re-export directly:
'from airflow.sdk.definitions.timetables._cron import CRON_PRESETS as cron_presets' in 'airflow/utils/dates.py'. The SDK is now the single source of truth ,no duplication, no sync needed.

@vatsrahul1001
Copy link
Copy Markdown
Contributor

@shashbha14 can you fix static checks

@shashbha14
Copy link
Copy Markdown
Contributor Author

@shashbha14 can you fix static checks

@shashbha14 can you fix static checks

Fixed — the static check was failing because the re-export approach
was blocked by the check-sdk-imports hook. Reverted to two separate
dicts with sync comments instead.

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

Labels

area:task-sdk backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CronMixin not supporting presets

5 participants