amoghrajesh commented on code in PR #54505:
URL: https://github.com/apache/airflow/pull/54505#discussion_r2556154491
##########
airflow-core/src/airflow/exceptions.py:
##########
@@ -519,19 +304,40 @@ def __init__(self, dag_id: str | None = None, message:
str | None = None):
super().__init__(f"An unexpected error occurred while trying to
deserialize Dag '{dag_id}'")
+_DEPRECATED_EXCEPTIONS = {
+ "AirflowTaskTerminated": "airflow.sdk.exceptions.AirflowTaskTerminated",
+ "DuplicateTaskIdFound": "airflow.sdk.exceptions.DuplicateTaskIdFound",
+ "FailFastDagInvalidTriggerRule":
"airflow.sdk.exceptions.FailFastDagInvalidTriggerRule",
+ "TaskAlreadyInTaskGroup": "airflow.sdk.exceptions.TaskAlreadyInTaskGroup",
+ "TaskDeferralTimeout": "airflow.sdk.exceptions.TaskDeferralTimeout",
+ "XComNotFound": "airflow.sdk.exceptions.XComNotFound",
+ "DownstreamTasksSkipped": "airflow.sdk.exceptions.DownstreamTasksSkipped",
+ "AirflowSensorTimeout": "airflow.sdk.exceptions.AirflowSensorTimeout",
+ "DagRunTriggerException": "airflow.sdk.exceptions.DagRunTriggerException",
+ "TaskDeferralError": "airflow.sdk.exceptions.TaskDeferralError",
+ "AirflowDagCycleException":
"airflow.sdk.exceptions.AirflowDagCycleException",
+ "AirflowInactiveAssetInInletOrOutletException":
"airflow.sdk.exceptions.AirflowInactiveAssetInInletOrOutletException",
+ "AirflowSkipException": "airflow.sdk.exceptions.AirflowSkipException",
+ "AirflowTaskTimeout": "airflow.sdk.exceptions.AirflowTaskTimeout",
+ "AirflowFailException": "airflow.sdk.exceptions.AirflowFailException",
+ "ParamValidationError": "airflow.sdk.exceptions.ParamValidationError",
+ "TaskDeferred": "airflow.sdk.exceptions.TaskDeferred",
+}
+
+
def __getattr__(name: str):
"""Provide backward compatibility for moved exceptions."""
- if name == "AirflowDagCycleException":
+ if name in _DEPRECATED_EXCEPTIONS:
import warnings
+ from importlib import import_module
+ from operator import attrgetter
- from airflow.sdk.exceptions import AirflowDagCycleException
-
+ target_path = _DEPRECATED_EXCEPTIONS[name]
warnings.warn(
- "airflow.exceptions.AirflowDagCycleException is deprecated. "
- "Use airflow.sdk.exceptions.AirflowDagCycleException instead.",
+ f"airflow.exceptions.{name} is deprecated. Use {target_path}
instead.",
DeprecationWarning,
stacklevel=2,
)
- return AirflowDagCycleException
-
+ module_path, attr_name = target_path.rsplit(".", 1)
+ return attrgetter(attr_name)(import_module(module_path))
Review Comment:
I was not suggesting `==` but `_DEPRECATED_EXCEPTIONS[name]` but thats OK,
whatever works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]