imrichardwu commented on code in PR #62583:
URL: https://github.com/apache/airflow/pull/62583#discussion_r3023650957
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/ui/deadline.py:
##########
@@ -44,3 +44,58 @@ class DeadlineCollectionResponse(BaseModel):
deadlines: Iterable[DeadlineResponse]
total_entries: int
+
+
+class DeadlineWithDagRunResponse(BaseModel):
+ """Deadline serializer for responses that includes DAG and DAG run
identifiers."""
+
+ id: UUID
+ deadline_time: datetime
+ missed: bool
+ created_at: datetime
+ dag_id: str = Field(validation_alias=AliasPath("dagrun", "dag_id"))
+ dag_run_id: str = Field(validation_alias=AliasPath("dagrun", "run_id"))
+ alert_name: str | None =
Field(validation_alias=AliasPath("deadline_alert", "name"), default=None)
+ alert_description: str | None = Field(
+ validation_alias=AliasPath("deadline_alert", "description"),
default=None
+ )
+
+
+class DeadlineWithDagRunCollectionResponse(BaseModel):
+ """Deadline Collection serializer for responses that includes DAG and DAG
run identifiers."""
+
+ deadlines: Iterable[DeadlineWithDagRunResponse]
+ total_entries: int
+
+
+class DeadlineAlertResponse(BaseModel):
+ """DeadlineAlert serializer for responses."""
+
+ id: UUID
+ name: str | None = None
+ description: str | None = None
+ reference_type: str
+ interval: float
+ created_at: datetime
+
+ @model_validator(mode="before")
+ @classmethod
+ def extract_reference_type(cls, data):
+ """Extract reference_type from the JSON reference column when
validating from an ORM object."""
+ if not isinstance(data, dict) and hasattr(data, "reference"):
+ return {
+ "id": data.id,
+ "name": data.name,
+ "description": data.description,
+ "reference_type": data.reference.get("reference_type", "") if
data.reference else "",
+ "interval": data.interval,
+ "created_at": data.created_at,
+ }
+ return data
Review Comment:
Just wondering, but is it always better to go declarative over imperative?
--
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]