-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Fix TypeError clearing a DAG run when a queued-at deadline interval is stored as JSON #70370
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
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 |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import dateutil.relativedelta | ||
|
|
||
| from airflow._shared.module_loading import import_string | ||
| from airflow.sdk.definitions.deadline import VariableInterval | ||
| from airflow.serialization.definitions.assets import ( | ||
| SerializedAsset, | ||
| SerializedAssetAlias, | ||
|
|
@@ -52,6 +53,7 @@ | |
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from airflow.models.deadline_alert import DeadlineAlert as DeadlineAlertModel | ||
| from airflow.partition_mappers.base import PartitionMapper | ||
| from airflow.partition_mappers.wait_policy import WaitPolicy | ||
| from airflow.partition_mappers.window import Window | ||
|
|
@@ -181,13 +183,12 @@ def decode_deadline_reference(reference_data: dict): | |
| return reference_class.deserialize_reference(reference_data) | ||
|
|
||
|
|
||
| def decode_deadline_alert(encoded_data: dict): | ||
| def decode_deadline_alert(encoded_data: dict) -> SerializedDeadlineAlert: | ||
| """ | ||
| Decode a previously serialized deadline alert. | ||
|
|
||
| :meta private: | ||
| """ | ||
| from airflow.sdk.definitions.deadline import VariableInterval | ||
| from airflow.sdk.serde import deserialize | ||
|
|
||
| data = encoded_data.get(Encoding.VAR, encoded_data) | ||
|
|
@@ -224,6 +225,35 @@ def decode_deadline_alert(encoded_data: dict): | |
| ) | ||
|
|
||
|
|
||
| def decode_deadline_alert_model(deadline_alert: DeadlineAlertModel) -> SerializedDeadlineAlert: | ||
| """ | ||
| Decode a ``DeadlineAlert`` ORM row into its serialized representation. | ||
|
|
||
| :meta private: | ||
| """ | ||
| return decode_deadline_alert( | ||
| { | ||
| DeadlineAlertFields.REFERENCE: deadline_alert.reference, | ||
| DeadlineAlertFields.INTERVAL: deadline_alert.interval, | ||
| DeadlineAlertFields.CALLBACK: deadline_alert.callback_def, | ||
| } | ||
| ) | ||
|
|
||
|
|
||
| def resolve_deadline_alert_interval(alert: SerializedDeadlineAlert) -> datetime.timedelta: | ||
| """ | ||
| Resolve a decoded alert's interval to a ``timedelta``. | ||
|
|
||
| A ``VariableInterval`` reads its Airflow Variable here, so this is only called at the point | ||
| a deadline is actually calculated. | ||
|
|
||
| :meta private: | ||
| """ | ||
| if isinstance(alert.interval, VariableInterval): | ||
| return alert.interval.resolve() | ||
|
Contributor
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. resolve() can raise |
||
| return alert.interval | ||
|
|
||
|
|
||
| def decode_timetable(var: dict[str, Any]) -> CoreTimetable: | ||
| """ | ||
| Decode a previously serialized timetable. | ||
|
|
||
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.
I'm not sure about this one. We moved this sdk import to the module level but left the other sdk import below it as a local?