Add name fields to deadline alerts#64926
Conversation
Updated deadline alert messages for clarity and consistency.
bbovenzi
left a comment
There was a problem hiding this comment.
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
providers/common/ai/src/airflow/providers/common/ai/plugins/www/__init__.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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
nameto the Task SDKDeadlineAlertand include it in core serialization encode/decode. - Persist
nameintoDeadlineAlertDB rows when creating alerts from serialized DAG data, and updatenamewhen reusing existing deadline UUIDs. - Remove
description/alert_descriptionfrom the UI API models and the generated UI OpenAPI client types; addDeadlinesto the UIMenuItemenum.
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 useDeadlineAlertFields.NAME. For consistency and to avoid drift/typos, consider usingDeadlineAlertFields.NAMEhere 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),
}
| 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.") |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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).
| 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), | ||
| ) | ||
| ) |
There was a problem hiding this comment.
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.
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?
{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.