Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dry run for backfill #45062

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
13 changes: 13 additions & 0 deletions airflow/api_fastapi/core_api/datamodels/backfills.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,16 @@ class BackfillCollectionResponse(BaseModel):

backfills: list[BackfillResponse]
total_entries: int


class DryRunBackfillResponse(BaseModel):
"""Data model for run information during a backfill operation."""

logical_date: datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will only have logical date, no data interval?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the logical date is a datetime, so for example for DAGs with schedules other than daily, the response will still include the dates on which the backfill will be triggered. I imagine that the user likely has an understanding of the dag's schedule when making a backfill request. Does including the data interval provide additional value in this context?

image

Copy link
Member

@uranusjr uranusjr Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data interval does not technically provide additional context; logical date is the only identifier when backfilling. With that said, I think the information is probably still convenient for the user since they wouldn’t need to check the schedule.



class DryRunBackfillCollectionResponse(BaseModel):
"""Serializer for responses in dry-run mode for backfill operations."""

backfills: list[DryRunBackfillResponse]
total_entries: int
76 changes: 76 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,55 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/backfills/dry_run:
post:
tags:
- Backfill
summary: Create Backfill Dry Run
operationId: create_backfill_dry_run
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/BackfillPostBody'
required: true
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/DryRunBackfillCollectionResponse'
'401':
description: Unauthorized
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'403':
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'404':
description: Not Found
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'409':
description: Conflict
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
/public/connections/{connection_id}:
delete:
tags:
Expand Down Expand Up @@ -7912,6 +7961,33 @@ components:
This is the set of allowable values for the ``warning_type`` field

in the DagWarning model.'
DryRunBackfillCollectionResponse:
properties:
backfills:
items:
$ref: '#/components/schemas/DryRunBackfillResponse'
type: array
title: Backfills
total_entries:
type: integer
title: Total Entries
type: object
required:
- backfills
- total_entries
title: DryRunBackfillCollectionResponse
description: Serializer for responses in dry-run mode for backfill operations.
DryRunBackfillResponse:
properties:
logical_date:
type: string
format: date-time
title: Logical Date
type: object
required:
- logical_date
title: DryRunBackfillResponse
description: Data model for run information during a backfill operation.
EdgeResponse:
properties:
is_setup_teardown:
Expand Down
39 changes: 39 additions & 0 deletions airflow/api_fastapi/core_api/routes/public/backfills.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
BackfillCollectionResponse,
BackfillPostBody,
BackfillResponse,
DryRunBackfillCollectionResponse,
DryRunBackfillResponse,
)
from airflow.api_fastapi.core_api.openapi.exceptions import (
create_openapi_http_exception_doc,
Expand Down Expand Up @@ -206,3 +208,40 @@ def create_backfill(
status_code=status.HTTP_409_CONFLICT,
detail=f"There is already a running backfill for dag {backfill_request.dag_id}",
)


@backfills_router.post(
path="/dry_run",
responses=create_openapi_http_exception_doc(
[
status.HTTP_404_NOT_FOUND,
status.HTTP_409_CONFLICT,
]
),
)
def create_backfill_dry_run(
body: BackfillPostBody,
) -> DryRunBackfillCollectionResponse:
from_date = timezone.coerce_datetime(body.from_date)
to_date = timezone.coerce_datetime(body.to_date)

try:
backfills_dry_run = _create_backfill(
dag_id=body.dag_id,
from_date=from_date,
to_date=to_date,
max_active_runs=body.max_active_runs,
reverse=body.run_backwards,
dag_run_conf=body.dag_run_conf,
reprocess_behavior=body.reprocess_behavior,
dry_run=True,
)
backfills = [DryRunBackfillResponse(logical_date=logical_date) for logical_date in backfills_dry_run]

return DryRunBackfillCollectionResponse(backfills=backfills, total_entries=len(backfills_dry_run))

except AlreadyRunningBackfill:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail="There is already a running backfill for the dag",
)
Loading