Skip to content

Commit

Permalink
Make logical_date nullable in API responses (apache#46666)
Browse files Browse the repository at this point in the history
  • Loading branch information
uranusjr authored Feb 12, 2025
1 parent 9ba45d1 commit 9c08dab
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 23 deletions.
2 changes: 1 addition & 1 deletion airflow/api_fastapi/core_api/datamodels/task_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion airflow/api_fastapi/core_api/datamodels/xcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 36 additions & 8 deletions airflow/ui/openapi-gen/requests/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
8 changes: 4 additions & 4 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion airflow/ui/src/components/TrendCountChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ 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");
const intervalSize = Math.floor(totalMinutes / 10);
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);

Expand Down

0 comments on commit 9c08dab

Please sign in to comment.