Skip to content

Commit f03f1e9

Browse files
github-actions[bot]rawwar
authored andcommitted
Use NonNegativeInt for backfill_id (#49691) (#49716)
* use NonNegativeInt for backfill_id * fix aws failing test * update BackfillResponse (cherry picked from commit e564f1b) Co-authored-by: Kalyan R <[email protected]>
1 parent 97754ea commit f03f1e9

File tree

20 files changed

+100
-32
lines changed

20 files changed

+100
-32
lines changed

airflow-core/src/airflow/api_fastapi/auth/managers/models/resource_details.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from dataclasses import dataclass
2121
from enum import Enum
2222

23+
from pydantic import NonNegativeInt
24+
2325

2426
@dataclass
2527
class ConfigurationDetails:
@@ -46,7 +48,7 @@ class DagDetails:
4648
class BackfillDetails:
4749
"""Represents the details of a backfill."""
4850

49-
id: str | None = None
51+
id: NonNegativeInt | None = None
5052

5153

5254
@dataclass

airflow-core/src/airflow/api_fastapi/core_api/datamodels/backfills.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
from datetime import datetime
2121

22+
from pydantic import NonNegativeInt
23+
2224
from airflow.api_fastapi.core_api.base import BaseModel, StrictBaseModel
2325
from airflow.models.backfill import ReprocessBehavior
2426

@@ -38,7 +40,7 @@ class BackfillPostBody(StrictBaseModel):
3840
class BackfillResponse(BaseModel):
3941
"""Base serializer for Backfill."""
4042

41-
id: int
43+
id: NonNegativeInt
4244
dag_id: str
4345
from_date: datetime
4446
to_date: datetime

airflow-core/src/airflow/api_fastapi/core_api/openapi/_private_ui.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ components:
595595
properties:
596596
id:
597597
type: integer
598+
minimum: 0.0
598599
title: Id
599600
dag_id:
600601
type: string

airflow-core/src/airflow/api_fastapi/core_api/openapi/v1-rest-api-generated.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,8 @@ paths:
951951
in: path
952952
required: true
953953
schema:
954-
type: string
954+
type: integer
955+
minimum: 0
955956
title: Backfill Id
956957
responses:
957958
'200':
@@ -997,6 +998,8 @@ paths:
997998
in: path
998999
required: true
9991000
schema:
1001+
type: integer
1002+
minimum: 0
10001003
title: Backfill Id
10011004
responses:
10021005
'200':
@@ -1048,6 +1051,8 @@ paths:
10481051
in: path
10491052
required: true
10501053
schema:
1054+
type: integer
1055+
minimum: 0
10511056
title: Backfill Id
10521057
responses:
10531058
'200':
@@ -1099,6 +1104,8 @@ paths:
10991104
in: path
11001105
required: true
11011106
schema:
1107+
type: integer
1108+
minimum: 0
11021109
title: Backfill Id
11031110
responses:
11041111
'200':
@@ -7039,6 +7046,7 @@ components:
70397046
properties:
70407047
id:
70417048
type: integer
7049+
minimum: 0.0
70427050
title: Id
70437051
dag_id:
70447052
type: string

airflow-core/src/airflow/api_fastapi/core_api/routes/public/backfills.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
from fastapi import Depends, HTTPException, status
2222
from fastapi.exceptions import RequestValidationError
23+
from pydantic import NonNegativeInt
2324
from sqlalchemy import select, update
2425

2526
from airflow.api_fastapi.auth.managers.models.resource_details import DagAccessEntity
@@ -98,7 +99,7 @@ def list_backfills(
9899
],
99100
)
100101
def get_backfill(
101-
backfill_id: str,
102+
backfill_id: NonNegativeInt,
102103
session: SessionDep,
103104
) -> BackfillResponse:
104105
backfill = session.get(Backfill, backfill_id)
@@ -121,7 +122,7 @@ def get_backfill(
121122
Depends(requires_access_dag(method="PUT", access_entity=DagAccessEntity.RUN)),
122123
],
123124
)
124-
def pause_backfill(backfill_id, session: SessionDep) -> BackfillResponse:
125+
def pause_backfill(backfill_id: NonNegativeInt, session: SessionDep) -> BackfillResponse:
125126
b = session.get(Backfill, backfill_id)
126127
if not b:
127128
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Could not find backfill with id {backfill_id}")
@@ -147,7 +148,7 @@ def pause_backfill(backfill_id, session: SessionDep) -> BackfillResponse:
147148
Depends(requires_access_dag(method="PUT", access_entity=DagAccessEntity.RUN)),
148149
],
149150
)
150-
def unpause_backfill(backfill_id, session: SessionDep) -> BackfillResponse:
151+
def unpause_backfill(backfill_id: NonNegativeInt, session: SessionDep) -> BackfillResponse:
151152
b = session.get(Backfill, backfill_id)
152153
if not b:
153154
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Could not find backfill with id {backfill_id}")
@@ -172,7 +173,7 @@ def unpause_backfill(backfill_id, session: SessionDep) -> BackfillResponse:
172173
Depends(requires_access_backfill(method="PUT")),
173174
],
174175
)
175-
def cancel_backfill(backfill_id, session: SessionDep) -> BackfillResponse:
176+
def cancel_backfill(backfill_id: NonNegativeInt, session: SessionDep) -> BackfillResponse:
176177
b: Backfill = session.get(Backfill, backfill_id)
177178
if not b:
178179
raise HTTPException(status.HTTP_404_NOT_FOUND, f"Could not find backfill with id {backfill_id}")

airflow-core/src/airflow/api_fastapi/core_api/security.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from fastapi import Depends, HTTPException, Request, status
2424
from fastapi.security import OAuth2PasswordBearer
2525
from jwt import ExpiredSignatureError, InvalidTokenError
26+
from pydantic import NonNegativeInt
2627

2728
from airflow.api_fastapi.app import get_auth_manager
2829
from airflow.api_fastapi.auth.managers.models.base_user import BaseUser
@@ -198,7 +199,7 @@ def inner(
198199
request: Request,
199200
user: Annotated[BaseUser | None, Depends(get_user)] = None,
200201
) -> None:
201-
backfill_id: str | None = request.path_params.get("backfill_id")
202+
backfill_id: NonNegativeInt | None = request.path_params.get("backfill_id")
202203

203204
_requires_access(
204205
is_authorized_callback=lambda: get_auth_manager().is_authorized_backfill(

airflow-core/src/airflow/models/dag.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
from airflow.utils.types import DagRunTriggeredByType, DagRunType
117117

118118
if TYPE_CHECKING:
119+
from pydantic import NonNegativeInt
119120
from sqlalchemy.orm.query import Query
120121
from sqlalchemy.orm.session import Session
121122

@@ -257,7 +258,7 @@ def _create_orm_dagrun(
257258
state: DagRunState | None,
258259
run_type: DagRunType,
259260
creating_job_id: int | None,
260-
backfill_id: int | None,
261+
backfill_id: NonNegativeInt | None,
261262
triggered_by: DagRunTriggeredByType,
262263
session: Session = NEW_SESSION,
263264
) -> DagRun:
@@ -1795,7 +1796,7 @@ def create_dagrun(
17951796
state: DagRunState,
17961797
start_date: datetime | None = None,
17971798
creating_job_id: int | None = None,
1798-
backfill_id: int | None = None,
1799+
backfill_id: NonNegativeInt | None = None,
17991800
session: Session = NEW_SESSION,
18001801
) -> DagRun:
18011802
"""

airflow-core/src/airflow/models/dagrun.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
from datetime import datetime
9494

9595
from opentelemetry.sdk.trace import Span
96+
from pydantic import NonNegativeInt
9697
from sqlalchemy.orm import Query, Session
9798

9899
from airflow.models.baseoperator import BaseOperator
@@ -290,7 +291,7 @@ def __init__(
290291
creating_job_id: int | None = None,
291292
data_interval: tuple[datetime, datetime] | None = None,
292293
triggered_by: DagRunTriggeredByType | None = None,
293-
backfill_id: int | None = None,
294+
backfill_id: NonNegativeInt | None = None,
294295
bundle_version: str | None = None,
295296
):
296297
# For manual runs where logical_date is None, ensure no data_interval is set.

airflow-core/src/airflow/ui/openapi-gen/queries/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export const UseBackfillServiceGetBackfillKeyFn = (
270270
{
271271
backfillId,
272272
}: {
273-
backfillId: string;
273+
backfillId: number;
274274
},
275275
queryKey?: Array<unknown>,
276276
) => [useBackfillServiceGetBackfillKey, ...(queryKey ?? [{ backfillId }])];

airflow-core/src/airflow/ui/openapi-gen/queries/ensureQueryData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export const ensureUseBackfillServiceGetBackfillData = (
354354
{
355355
backfillId,
356356
}: {
357-
backfillId: string;
357+
backfillId: number;
358358
},
359359
) =>
360360
queryClient.ensureQueryData({

0 commit comments

Comments
 (0)