This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 9c08dab6c50 Make logical_date nullable in API responses (#46666)
9c08dab6c50 is described below

commit 9c08dab6c5050c72f353904ab0bd299ac085170f
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Thu Feb 13 02:06:02 2025 +0800

    Make logical_date nullable in API responses (#46666)
---
 .../core_api/datamodels/task_instances.py          |  2 +-
 airflow/api_fastapi/core_api/datamodels/xcom.py    |  2 +-
 .../api_fastapi/core_api/openapi/v1-generated.yaml | 24 ++++++++----
 airflow/ui/openapi-gen/requests/schemas.gen.ts     | 44 ++++++++++++++++++----
 airflow/ui/openapi-gen/requests/types.gen.ts       |  8 ++--
 airflow/ui/src/components/TrendCountChart.tsx      |  5 ++-
 6 files changed, 62 insertions(+), 23 deletions(-)

diff --git a/airflow/api_fastapi/core_api/datamodels/task_instances.py 
b/airflow/api_fastapi/core_api/datamodels/task_instances.py
index d209d46bd5e..7c849a9e86a 100644
--- a/airflow/api_fastapi/core_api/datamodels/task_instances.py
+++ b/airflow/api_fastapi/core_api/datamodels/task_instances.py
@@ -46,7 +46,7 @@ class TaskInstanceResponse(BaseModel):
     dag_id: str
     run_id: str = Field(alias="dag_run_id")
     map_index: int
-    logical_date: datetime
+    logical_date: datetime | None
     start_date: datetime | None
     end_date: datetime | None
     duration: float | None
diff --git a/airflow/api_fastapi/core_api/datamodels/xcom.py 
b/airflow/api_fastapi/core_api/datamodels/xcom.py
index 1acccb702ef..189fad8290c 100644
--- a/airflow/api_fastapi/core_api/datamodels/xcom.py
+++ b/airflow/api_fastapi/core_api/datamodels/xcom.py
@@ -29,7 +29,7 @@ class XComResponse(BaseModel):
 
     key: str
     timestamp: datetime
-    logical_date: datetime
+    logical_date: datetime | None
     map_index: int
     task_id: str
     dag_id: str
diff --git a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml 
b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
index 342274aacc3..44aac872412 100644
--- a/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
+++ b/airflow/api_fastapi/core_api/openapi/v1-generated.yaml
@@ -9957,8 +9957,10 @@ components:
           type: integer
           title: Map Index
         logical_date:
-          type: string
-          format: date-time
+          anyOf:
+          - type: string
+            format: date-time
+          - type: 'null'
           title: Logical Date
         start_date:
           anyOf:
@@ -10765,8 +10767,10 @@ components:
           format: date-time
           title: Timestamp
         logical_date:
-          type: string
-          format: date-time
+          anyOf:
+          - type: string
+            format: date-time
+          - type: 'null'
           title: Logical Date
         map_index:
           type: integer
@@ -10801,8 +10805,10 @@ components:
           format: date-time
           title: Timestamp
         logical_date:
-          type: string
-          format: date-time
+          anyOf:
+          - type: string
+            format: date-time
+          - type: 'null'
           title: Logical Date
         map_index:
           type: integer
@@ -10840,8 +10846,10 @@ components:
           format: date-time
           title: Timestamp
         logical_date:
-          type: string
-          format: date-time
+          anyOf:
+          - type: string
+            format: date-time
+          - type: 'null'
           title: Logical Date
         map_index:
           type: integer
diff --git a/airflow/ui/openapi-gen/requests/schemas.gen.ts 
b/airflow/ui/openapi-gen/requests/schemas.gen.ts
index e1fa4322c21..f0d56a19552 100644
--- a/airflow/ui/openapi-gen/requests/schemas.gen.ts
+++ b/airflow/ui/openapi-gen/requests/schemas.gen.ts
@@ -4817,8 +4817,15 @@ export const $TaskInstanceResponse = {
       title: "Map Index",
     },
     logical_date: {
-      type: "string",
-      format: "date-time",
+      anyOf: [
+        {
+          type: "string",
+          format: "date-time",
+        },
+        {
+          type: "null",
+        },
+      ],
       title: "Logical Date",
     },
     start_date: {
@@ -6144,8 +6151,15 @@ export const $XComResponse = {
       title: "Timestamp",
     },
     logical_date: {
-      type: "string",
-      format: "date-time",
+      anyOf: [
+        {
+          type: "string",
+          format: "date-time",
+        },
+        {
+          type: "null",
+        },
+      ],
       title: "Logical Date",
     },
     map_index: {
@@ -6183,8 +6197,15 @@ export const $XComResponseNative = {
       title: "Timestamp",
     },
     logical_date: {
-      type: "string",
-      format: "date-time",
+      anyOf: [
+        {
+          type: "string",
+          format: "date-time",
+        },
+        {
+          type: "null",
+        },
+      ],
       title: "Logical Date",
     },
     map_index: {
@@ -6225,8 +6246,15 @@ export const $XComResponseString = {
       title: "Timestamp",
     },
     logical_date: {
-      type: "string",
-      format: "date-time",
+      anyOf: [
+        {
+          type: "string",
+          format: "date-time",
+        },
+        {
+          type: "null",
+        },
+      ],
       title: "Logical Date",
     },
     map_index: {
diff --git a/airflow/ui/openapi-gen/requests/types.gen.ts 
b/airflow/ui/openapi-gen/requests/types.gen.ts
index 315fc26dfac..18a66636820 100644
--- a/airflow/ui/openapi-gen/requests/types.gen.ts
+++ b/airflow/ui/openapi-gen/requests/types.gen.ts
@@ -1252,7 +1252,7 @@ export type TaskInstanceResponse = {
   dag_id: string;
   dag_run_id: string;
   map_index: number;
-  logical_date: string;
+  logical_date: string | null;
   start_date: string | null;
   end_date: string | null;
   duration: number | null;
@@ -1510,7 +1510,7 @@ export type XComCreateBody = {
 export type XComResponse = {
   key: string;
   timestamp: string;
-  logical_date: string;
+  logical_date: string | null;
   map_index: number;
   task_id: string;
   dag_id: string;
@@ -1523,7 +1523,7 @@ export type XComResponse = {
 export type XComResponseNative = {
   key: string;
   timestamp: string;
-  logical_date: string;
+  logical_date: string | null;
   map_index: number;
   task_id: string;
   dag_id: string;
@@ -1537,7 +1537,7 @@ export type XComResponseNative = {
 export type XComResponseString = {
   key: string;
   timestamp: string;
-  logical_date: string;
+  logical_date: string | null;
   map_index: number;
   task_id: string;
   dag_id: string;
diff --git a/airflow/ui/src/components/TrendCountChart.tsx 
b/airflow/ui/src/components/TrendCountChart.tsx
index a30d44b467b..483fe9efb6b 100644
--- a/airflow/ui/src/components/TrendCountChart.tsx
+++ b/airflow/ui/src/components/TrendCountChart.tsx
@@ -35,7 +35,7 @@ import { useColorMode } from "src/context/colorMode";
 
 ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, 
Filler, Tooltip);
 
-export type ChartEvent = { timestamp: string };
+export type ChartEvent = { timestamp: string | null };
 
 const aggregateEventsIntoIntervals = (events: Array<ChartEvent>, startDate: 
string, endDate: string) => {
   const totalMinutes = dayjs(endDate).diff(startDate, "minutes");
@@ -43,6 +43,9 @@ const aggregateEventsIntoIntervals = (events: 
Array<ChartEvent>, startDate: stri
   const intervals = Array.from({ length: 10 }).fill(0) as Array<number>;
 
   events.forEach((event) => {
+    if (event.timestamp === null) {
+      return;
+    }
     const minutesSinceStart = dayjs(event.timestamp).diff(startDate, 
"minutes");
     const intervalIndex = Math.min(Math.floor(minutesSinceStart / 
intervalSize), 9);
 

Reply via email to