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

Conversation

prabhusneha
Copy link
Contributor

Closes #44395

Response:
image

@boring-cyborg boring-cyborg bot added the area:UI Related to UI/UX. For Frontend Developers. label Dec 18, 2024
@phanikumv phanikumv requested a review from dstandish December 19, 2024 13:59
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

As discussed with daniel, maybe a separate endpoint makes more sense to avoid mixed returned type BackfillResponse | BackfillDryRunResponse on the same endpoint. That's hard to handle for clients.

@prabhusneha
Copy link
Contributor Author

As discussed with daniel, maybe a separate endpoint makes more sense to avoid mixed returned type BackfillResponse | BackfillDryRunResponse on the same endpoint. That's hard to handle for clients.

Created a separate endpoint for dry run.

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

Thanks, looking nice.

A few improvement suggestions.

airflow/api_fastapi/core_api/routes/public/backfills.py Outdated Show resolved Hide resolved
airflow/api_fastapi/core_api/routes/public/backfills.py Outdated Show resolved Hide resolved
airflow/api_fastapi/core_api/routes/public/backfills.py Outdated Show resolved Hide resolved
airflow/api_fastapi/core_api/routes/public/backfills.py Outdated Show resolved Hide resolved
airflow/api_fastapi/core_api/datamodels/backfills.py Outdated Show resolved Hide resolved
@jscheffl
Copy link
Contributor

jscheffl commented Jan 1, 2025

Note: As PR #45312 has been merged, the code formatting rules have changed for new UI. Please rebase and re-run pre-commit checks to ensure that formatting in folder airflow/ui is adjusted.

Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

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

Overall looking good.

A few suggestions.

I would wait for @dstandish approval before merging that, just to be sure that the backfill logic is correct. (It looks good to me)

).all()
}

print(existing_dag_runs)
Copy link
Member

Choose a reason for hiding this comment

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

to remove print statements

from airflow.utils.state import DagRunState
from airflow.utils.types import DagRunTriggeredByType, DagRunType

if TYPE_CHECKING:
from datetime import datetime

from typing_extensions import Literal
Copy link
Member

Choose a reason for hiding this comment

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

Import Literal from typing

session=session,
backfill_sort_ordinal = 0
logical_dates = []
dagrun_infos = list(dagrun_info_list)
Copy link
Member

Choose a reason for hiding this comment

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

I think we need to slightly modify _get_info_list to not have to explicitely cast to dict. Also we can add types. ( -> list[DagRunInfo])

Comment on lines +193 to +204
.join(
dag_run_ranked,
(DagRun.logical_date == dag_run_ranked.c.logical_date)
& (
(DagRun.start_date == dag_run_ranked.c.start_date)
| ((DagRun.start_date.is_(None)) & (dag_run_ranked.c.start_date.is_(None)))
)
& (DagRun.dag_id == dag_run_ranked.c.dag_id),
)
.where(dag_run_ranked.c.row_number == 1)
).all()
}
Copy link
Member

Choose a reason for hiding this comment

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

I assume all that is necessary because of the removal of the unique constraint on the logical_date ?

What are the update on that ?

cc: @dstandish

Comment on lines +194 to +202
dag_run_ranked,
(DagRun.logical_date == dag_run_ranked.c.logical_date)
& (
(DagRun.start_date == dag_run_ranked.c.start_date)
| ((DagRun.start_date.is_(None)) & (dag_run_ranked.c.start_date.is_(None)))
)
& (DagRun.dag_id == dag_run_ranked.c.dag_id),
)
.where(dag_run_ranked.c.row_number == 1)
Copy link
Member

Choose a reason for hiding this comment

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

sqlalchemy has and and or function and this is what I usually see in the codebase. I don't use binary & and | I'm not sure it always behaves as we expect.

Comment on lines +223 to +226
if non_create_reason:
if not dry_run:
nested.rollback()
session.add(
Copy link
Member

Choose a reason for hiding this comment

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

I think that a usefull comment was removed:

               # rolling back here restores to start of this nested tran
                # which releases the lock on the latest dag run, since we
                # are not creating a new one



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

Choose a reason for hiding this comment

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

Nit:

Suggested change
"""Data model for run information during a backfill operation."""
"""Backfill serializer for responses in dry-run mode. """



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

Choose a reason for hiding this comment

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

Suggested change
"""Serializer for responses in dry-run mode for backfill operations."""
"""Backfill collection serializer for responses in dry-run mode."""

)
return br

backfill_response = _create_backfill_dag_run(
Copy link
Member

Choose a reason for hiding this comment

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

backfill_response that variable name is not great. This makes me think of an http response.

maybe logical_dates is more natural ?

reprocess_behavior=body.reprocess_behavior,
dry_run=True,
)
backfills = [DryRunBackfillResponse(logical_date=logical_date) for logical_date in backfills_dry_run]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
backfills = [DryRunBackfillResponse(logical_date=logical_date) for logical_date in backfills_dry_run]
backfills = [DryRunBackfillResponse(logical_date=d) for d in backfills_dry_run]

@@ -158,72 +151,125 @@ def validate_sort_ordinal(self, key, val):
def _create_backfill_dag_run(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you not make changes to this function but just keep it simple and essentially do the following:

Do just like done for CLI, i.e. in _do_dry_run, but add the extra step of checking whether it would actually create the run? I.e. extra logic check for existence?

We can use the same function for both cli and api.

essentially, we just need to return the list "these rows would be created". I don't think we need to modify the path where we actually create the runs at this time. Let me know what you think of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:UI Related to UI/UX. For Frontend Developers.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add robust dry run capability for backfill
6 participants