Skip to content

Add name fields to deadline alerts#64926

Open
imrichardwu wants to merge 9 commits intoapache:mainfrom
imrichardwu:deadlines-serialization
Open

Add name fields to deadline alerts#64926
imrichardwu wants to merge 9 commits intoapache:mainfrom
imrichardwu:deadlines-serialization

Conversation

@imrichardwu
Copy link
Copy Markdown
Contributor

@imrichardwu imrichardwu commented Apr 8, 2026

Adds name and description fields to DeadlineAlert, exposed through the API. (json edited files are for ui change for my pr in the future) @bbovenzi


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Copy link
Copy Markdown
Contributor

@bbovenzi bbovenzi left a comment

Choose a reason for hiding this comment

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

Let's remove the i18n json and browse tab changes. Those are better to stay with their UI branches.

Also, given that we made the interval + reference more readable in your other PR. I feel like description is no longer necessary. Let's just do name

@imrichardwu imrichardwu requested a review from bbovenzi April 9, 2026 16:41
@imrichardwu imrichardwu changed the title Add name and description fields to deadline alerts Add name fields to deadline alerts Apr 9, 2026
@kaxil kaxil requested a review from Copilot April 10, 2026 19:55
Copy link
Copy Markdown
Contributor

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

Propagates DeadlineAlert.name through SDK/core serialization into the metadata DB and adjusts the UI API/OpenAPI shapes for deadline-related responses.

Changes:

  • Add optional name to the Task SDK DeadlineAlert and include it in core serialization encode/decode.
  • Persist name into DeadlineAlert DB rows when creating alerts from serialized DAG data, and update name when reusing existing deadline UUIDs.
  • Remove description / alert_description from the UI API models and the generated UI OpenAPI client types; add Deadlines to the UI MenuItem enum.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
task-sdk/src/airflow/sdk/definitions/deadline.py Adds optional name to SDK DeadlineAlert.
airflow-core/src/airflow/serialization/encoders.py Emits name in serialized deadline alert payloads.
airflow-core/src/airflow/serialization/decoders.py Parses name from serialized deadline alert payloads.
airflow-core/src/airflow/serialization/definitions/deadline.py Adds field constant + name to SerializedDeadlineAlert.
airflow-core/src/airflow/models/serialized_dag.py Writes/updates DeadlineAlertModel.name when persisting serialized DAGs.
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/deadline.py Removes description fields from UI API response models.
airflow-core/src/airflow/api_fastapi/common/types.py Adds DEADLINES to MenuItem.
airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml Removes description fields from schemas; adds Deadlines to menu enum.
airflow-core/src/airflow/ui/openapi-gen/requests/types.gen.ts Regenerated client types (drops description fields; adds Deadlines).
airflow-core/src/airflow/ui/openapi-gen/requests/schemas.gen.ts Regenerated client schemas (drops description fields; adds Deadlines).
airflow-core/tests/unit/models/test_deadline_alert.py Removes assertions/data for description.
airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_deadlines.py Removes alert_description assertions and related test naming/docs.
Comments suppressed due to low confidence (1)

airflow-core/src/airflow/serialization/encoders.py:218

  • encode_deadline_alert() uses a literal "name" key while the decoder and other call sites use DeadlineAlertFields.NAME. For consistency and to avoid drift/typos, consider using DeadlineAlertFields.NAME here as well.
    from airflow.sdk.serde import serialize

    return {
        "name": getattr(d, "name", None),
        "reference": encode_deadline_reference(d.reference),
        "interval": d.interval.total_seconds(),
        "callback": serialize(d.callback),
    }

Comment on lines 48 to 54
class DeadlineAlertResponse(BaseModel):
"""DeadlineAlert serializer for responses."""

id: UUID
name: str | None = None
description: str | None = None
reference_type: str = Field(validation_alias=AliasPath("reference", "reference_type"))
interval: float = Field(description="Interval in seconds between deadline evaluations.")
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

PR description says the API will expose both name and description on DeadlineAlert, but this change removes description from the UI API response models (and corresponding OpenAPI). Either update the PR description to match the actual behavior, or reintroduce description in the response models/OpenAPI if it should remain supported.

Copilot uses AI. Check for mistakes.
Comment on lines 579 to 592
if deadline_uuid_mapping is not None:
# All deadlines matched — reuse the UUIDs to preserve hash.
# Clear the mapping since the alert rows already exist in the DB;
# no need to delete and recreate identical records.
# Update name in case it changed (it doesn't affect the definition
# match or the hash, so existing rows won't be recreated, but it
# must stay current in the DB).
for uuid_str, deadline_data in deadline_uuid_mapping.items():
session.execute(
update(DeadlineAlertModel)
.where(DeadlineAlertModel.id == UUID(uuid_str))
.values(
name=deadline_data.get(DeadlineAlertFields.NAME),
)
)
dag.data["dag"]["deadline"] = existing_deadline_uuids
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

This block executes UPDATE deadline_alert SET name=... even when the serialized DAG hash is unchanged, but write_dag() can still return False later (meaning "not written"). That makes the return value misleading and can hide that a DB write occurred; consider tracking whether any name updates were applied and returning True (or adjusting the control flow/docstring accordingly).

Copilot uses AI. Check for mistakes.
Comment on lines 579 to +591
if deadline_uuid_mapping is not None:
# All deadlines matched — reuse the UUIDs to preserve hash.
# Clear the mapping since the alert rows already exist in the DB;
# no need to delete and recreate identical records.
# Update name in case it changed (it doesn't affect the definition
# match or the hash, so existing rows won't be recreated, but it
# must stay current in the DB).
for uuid_str, deadline_data in deadline_uuid_mapping.items():
session.execute(
update(DeadlineAlertModel)
.where(DeadlineAlertModel.id == UUID(uuid_str))
.values(
name=deadline_data.get(DeadlineAlertFields.NAME),
)
)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

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

New behavior: when deadline UUIDs are reused, write_dag() now updates DeadlineAlertModel.name even if the serialized DAG hash doesn't change. There doesn't appear to be a unit test covering this path (e.g., name changes while reference/interval/callback stay the same), so a regression test should be added to ensure the DB row is updated and the returned value/side-effects are as expected.

Copilot generated this review using guidance from repository custom instructions.
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.

3 participants