Skip to content

Add type-checking guards to DeadlineAlert init - #73294

Merged
ferruzzi merged 6 commits into
apache:mainfrom
aws-mwaa:ferruzzi/deadlines/tighten-init-typing
Sep 22, 2026
Merged

ferruzzi merged 6 commits into
apache:mainfrom
aws-mwaa:ferruzzi/deadlines/tighten-init-typing

Conversation

@ferruzzi

@ferruzzi ferruzzi commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

## Must land after #72651 (merged)

#72651 made the scheduler decode deadline intervals and callbacks by exact class name. This adds the matching validation on the write side, so a Dag author is refused at parse time instead of the scheduler failing later on a row it cannot read.

  • DeadlineAlert.__init__ now refuses a callback that is not exactly AsyncCallback or SyncCallback, since the decoder allow-lists those by class name and a subclass could be written but never read back.
  • DeadlineAlert.__init__ validates interval. Numbers are deprecated, not rejected: accepted as seconds with a RemovedInAirflow4Warning, because interval=3600 parses today. timedelta subclasses such as pendulum.duration(...) are normalized to a plain timedelta instead of failing later in serde. interval=True is refused.
  • serialization/decoders.py builds its allow-list from a shared DEADLINE_CALLBACK_TYPES instead of keeping a second copy of the pair.

Added a significant newsfragment for the deprecation and the callback tightening, and unit testing for the above

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had just one thing to point out.

Comment thread task-sdk/src/airflow/sdk/definitions/deadline.py
@ferruzzi ferruzzi added this to the Airflow 3.3.3 milestone Sep 21, 2026
@ferruzzi ferruzzi added the backport-to-v3-3-test Backport to v3-3-test label Sep 21, 2026

@potiuk potiuk left a comment

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.

Approving — the guards are a real improvement, and I checked that the reasoning behind the strict callback check holds: _decode_deadline_callback allow-lists AsyncCallback and SyncCallback by qualified class name, so a Callback subclass that passed the old isinstance check only blew up later, at deserialization. Moving that to Dag-parse time is the right call, and the comment recording why isinstance is too loose earns its place.

I'm not gating the merge on the points below, but I would like them fixed — the first two are decisions rather than polish:

  • deadline.py:157 — a bare int interval round-trips end to end today (the decoder has a back-compat branch for numbers); this guard rejects it, and the PR carries backport-to-v3-3-test. Normalise it, or drop the backport label and add a newsfragment.
  • deadline.py:162 — the comment's own argument applies to the interval check too: pendulum.duration(...) subclasses timedelta, passes the guard, then dies in serde with a TypeError. Normalising subclasses would make it work instead of failing late.
  • deadline.py:154 — narrow callback: Callback to AsyncCallback | SyncCallback, so mypy catches the subclass case statically.
  • deadline.py:163 — the permitted-callback tuple now duplicates the decoder's allow-list; tie both to one constant.
  • test_deadline.py:237 — the interval test never asserts the reported type name, unlike its callback sibling.

Details inline.

Smaller observations

  • The PR body says "Adds a couple unit tests…", but the diff also changes two production validation paths in a backport-labelled PR. Worth a line in the description — backport reviewers read it.
  • test_serialize_deserialize_deadline_alert: switching the third case to SerializedDeadlineAlert is the right resolution of @SameerMesiah97's point, and gives better coverage of the core-side round trip. The param id serialized_variable_interval now describes a different case though — something like core_serialized_alert would read truer.
  • No newsfragment is correct as the PR stands, since the subclass and loose-type cases already failed at (de)serialization. That answer changes if the int rejection above is kept as-is.

This review was drafted by an AI-assisted tool and
confirmed by an Airflow maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.

More on how Airflow handles maintainer review:
contributing-docs/05_pull_requests.rst.

Comment thread task-sdk/src/airflow/sdk/definitions/deadline.py
Comment thread task-sdk/src/airflow/sdk/definitions/deadline.py
Comment thread task-sdk/src/airflow/sdk/definitions/deadline.py Outdated
Comment thread task-sdk/src/airflow/sdk/definitions/deadline.py Outdated
Comment thread task-sdk/tests/task_sdk/definitions/test_deadline.py Outdated
@ferruzzi
ferruzzi force-pushed the ferruzzi/deadlines/tighten-init-typing branch from f084e40 to a325e2b Compare September 21, 2026 23:42
@ferruzzi
ferruzzi merged commit b9e46d6 into apache:main Sep 22, 2026
205 of 206 checks passed
@ferruzzi
ferruzzi deleted the ferruzzi/deadlines/tighten-init-typing branch September 22, 2026 22:21
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-3-test PR Link

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

Labels

area:deadline-alerts AIP-86 (former AIP-57) area:task-sdk backport-to-v3-3-test Backport to v3-3-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants