Lee-W commented on code in PR #58248:
URL: https://github.com/apache/airflow/pull/58248#discussion_r2521812540
##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1259,11 +1260,15 @@ def recalculate(self) -> _UnfinishedStates:
msg="success",
)
- if dag.deadline:
+ if dag.deadline and isinstance(dag.deadline[0], str):
Review Comment:
Would love to know what is this check for?
##########
airflow-core/src/airflow/models/deadline_alert.py:
##########
@@ -0,0 +1,101 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from datetime import datetime
+from typing import TYPE_CHECKING
+
+import uuid6
+from sqlalchemy import JSON, Float, ForeignKey, String, Text, select
+from sqlalchemy.orm import Mapped
+from sqlalchemy_utils import UUIDType
+
+from airflow._shared.timezones import timezone
+from airflow.models import Base
+from airflow.models.deadline import ReferenceModels
+from airflow.utils.session import NEW_SESSION, provide_session
+from airflow.utils.sqlalchemy import UtcDateTime, mapped_column
+
+if TYPE_CHECKING:
+ from sqlalchemy.orm import Session
+
+
+class DeadlineAlert(Base):
+ """Table containing DeadlineAlert properties."""
+
+ __tablename__ = "deadline_alert"
+
+ id: Mapped[str] = mapped_column(UUIDType(binary=False), primary_key=True,
default=uuid6.uuid7)
+ created_at: Mapped[datetime] = mapped_column(UtcDateTime, nullable=False,
default=timezone.utcnow)
+
+ serialized_dag_id: Mapped[str] = mapped_column(
Review Comment:
Why ser_Dag instead of Dag
##########
airflow-core/src/airflow/migrations/versions/0094_3_2_0_ui_improvements_for_deadlines.py:
##########
@@ -0,0 +1,563 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+Add required fields to enable UI integrations for the Deadline Alerts feature.
+
+This migration creates the deadline_alert table to store DeadlineAlert
definitions
+and migrates existing Deadline Alert data from the serialized_dag JSON
structure
+into the new normalized table structure.
+
+Revision ID: 55297ae24532
+Revises: 665854ef0536
+Create Date: 2025-10-17 16:04:55.016272
+"""
+
+from __future__ import annotations
+
+import json
+import zlib
+from collections import defaultdict
+from typing import TYPE_CHECKING
+
+import sqlalchemy as sa
+import uuid6
+from alembic import op
+from sqlalchemy_utils import UUIDType
+
+from airflow._shared.timezones import timezone
+from airflow.migrations.db_types import TIMESTAMP
+from airflow.utils.sqlalchemy import UtcDateTime
+
+if TYPE_CHECKING:
+ from typing import Any
+
+ from sqlalchemy.engine import Connection
+
+ ErrorDict = dict[str, list[str]]
+
+revision = "55297ae24532"
+down_revision = "665854ef0536"
+branch_labels = None
+depends_on = None
+airflow_version = "3.2.0"
+
+
+DEADLINE_ALERT_REQUIRED_FIELDS = {"reference", "callback", "interval"}
+CALLBACK_KEY = "callback"
+DAG_KEY = "dag"
+DEADLINE_KEY = "deadline"
+INTERVAL_KEY = "interval"
+REFERENCE_KEY = "reference"
+DEFAULT_BATCH_SIZE = 1000
+ENCODING_TYPE = "deadline_alert"
+
+
+def upgrade() -> None:
+ """Make changes to enable adding DeadlineAlerts to the UI."""
+ # TODO: We may finally have come up with a better naming convention. For
ease of migration,
+ # we are going to keep deadline_alert here to match the model's name,
but in the near future
+ # when this migration work is done we should deprecate the name
DeadlineAlert (and all related
+ # classes, tables, etc) and replace it with DeadlineDefinition. Then we
will have the
+ # user-provided DeadlineDefinition, and the actual instance of a
Definition is (still) the Deadline.
+ # This feels more intuitive than DeadlineAlert defining the Deadline.
+
+ op.create_table(
+ "deadline_alert",
+ sa.Column("id", UUIDType(binary=False), default=uuid6.uuid7),
+ sa.Column(
+ "created_at", UtcDateTime, nullable=False,
server_default=sa.text("timezone('utc', now())")
+ ),
+ sa.Column("serialized_dag_id", UUIDType(binary=False), nullable=False),
+ sa.Column("name", sa.String(250), nullable=True),
+ sa.Column("description", sa.Text(), nullable=True),
+ sa.Column("reference", sa.JSON(), nullable=False),
+ sa.Column("interval", sa.Float(), nullable=False),
+ sa.Column("callback", sa.JSON(), nullable=False),
+ sa.PrimaryKeyConstraint("id", name=op.f("deadline_alert_pkey")),
+ )
+
+ with op.batch_alter_table("deadline", schema=None) as batch_op:
+ batch_op.add_column(sa.Column("deadline_alert_id",
UUIDType(binary=False), nullable=True))
+ batch_op.add_column(
+ sa.Column("created_at", TIMESTAMP(timezone=True), nullable=False,
server_default=sa.func.now())
+ )
+ batch_op.add_column(
+ sa.Column(
+ "last_updated_at", TIMESTAMP(timezone=True), nullable=False,
server_default=sa.func.now()
+ )
+ )
+
+ op.create_foreign_key(
+ op.f("deadline_deadline_alert_id_fkey"),
+ "deadline",
+ "deadline_alert",
+ ["deadline_alert_id"],
+ ["id"],
+ ondelete="SET NULL",
+ )
+
+ op.create_foreign_key(
+ op.f("deadline_alert_serialized_dag_id_fkey"),
+ "deadline_alert",
+ "serialized_dag",
+ ["serialized_dag_id"],
+ ["id"],
+ ondelete="CASCADE",
+ )
+
+ migrate_existing_deadline_alert_data_from_serialized_dag()
+
+
+def downgrade() -> None:
+ """Remove changes that were added to enable adding DeadlineAlerts to the
UI."""
+ migrate_deadline_alert_data_back_to_serialized_dag()
+
+ op.drop_constraint(op.f("deadline_deadline_alert_id_fkey"), "deadline",
type_="foreignkey")
Review Comment:
we'll need to to `"PRAGMA foreign_keys=OFF"` for sqlite. otherwise, it might
break
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]