-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
AIP-83 run_id logic when no logical date #46398
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,7 +88,8 @@ def autogenerate(self, data, **kwargs): | |
if "dag_run_id" not in data: | ||
try: | ||
data["dag_run_id"] = DagRun.generate_run_id( | ||
DagRunType.MANUAL, timezone.parse(data["logical_date"]) | ||
DagRunType.MANUAL, | ||
timezone.parse(data["logical_date"]), | ||
) | ||
Comment on lines
90
to
93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to pass run_after here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like there is no change here, just a new line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes and I think that’s wrong, we should change the logic here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required here? as |
||
except (ParserError, TypeError) as err: | ||
raise BadRequest("Incorrect datetime argument", detail=str(err)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,6 +371,7 @@ def trigger_dag_run( | |
run_type=DagRunType.MANUAL, | ||
logical_date=logical_date, | ||
data_interval=data_interval, | ||
run_after=data_interval.end, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, if logical date is null, then we won't generally have a data interval.... correct @uranusjr ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. data_interval would be null as well. |
||
) | ||
|
||
dag_run = dag.create_dagrun( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1281,6 +1281,7 @@ def _create_dag_runs(self, dag_models: Collection[DagModel], session: Session) - | |
run_type=DagRunType.SCHEDULED, | ||
logical_date=dag_model.next_dagrun, | ||
data_interval=data_interval, | ||
run_after=dag_model.next_dagrun_create_after, | ||
), | ||
logical_date=dag_model.next_dagrun, | ||
data_interval=data_interval, | ||
|
@@ -1391,6 +1392,7 @@ def _create_dag_runs_asset_triggered( | |
run_type=DagRunType.ASSET_TRIGGERED, | ||
logical_date=logical_date, | ||
data_interval=data_interval, | ||
run_after=max(logical_dates.values()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There’s a task to make asset-triggered runs have None logical_date instead, so we’ll need to change this again soon. This is good enough for now. |
||
session=session, | ||
events=asset_events, | ||
), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
from typing import TYPE_CHECKING, TypedDict | ||
|
||
import airflow.sdk.definitions._internal.types | ||
from airflow.utils.strings import get_random_string | ||
|
||
if TYPE_CHECKING: | ||
from datetime import datetime | ||
|
@@ -42,7 +43,11 @@ class DagRunType(str, enum.Enum): | |
def __str__(self) -> str: | ||
return self.value | ||
|
||
def generate_run_id(self, logical_date: datetime) -> str: | ||
def generate_run_id(self, logical_date: datetime | None, run_after: datetime | None) -> str: | ||
if logical_date is None: | ||
if run_after is None: | ||
raise ValueError("run_after cannot be None") | ||
return run_after + get_random_string() | ||
return f"{self}__{logical_date.isoformat()}" | ||
Comment on lines
-45
to
51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe if this function should continue to accept one single datetime value, and we do the if-else check outside instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. run_after could be None as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can’t There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here we need to know if logical_date is None or not before generating a random string that gets appended to run_after. |
||
|
||
@staticmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point (before 3.0) I want to reduce the arguments here to just take a DagRunInfo, but that can be done separately instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the doc, when logical date is null, then data interval end should be null. so it would not make sense to use data interval end as the run_after date. thoughts @uranusjr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah you’re right. This should do
coerced_logical_date or timezone.utcnow()
(as currently implemented,coerced_logical_date
can never be None, but it will be when everything is finished).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we include this change as a part of this PR or have a separate PR?