ephraimbuddy commented on code in PR #54505:
URL: https://github.com/apache/airflow/pull/54505#discussion_r2555582643


##########
airflow-core/src/airflow/exceptions.py:
##########
@@ -21,29 +21,35 @@
 
 from __future__ import annotations
 
-from collections.abc import Collection, Sequence
-from datetime import datetime, timedelta
+import os
 from http import HTTPStatus
-from typing import TYPE_CHECKING, Any, NamedTuple
+from typing import TYPE_CHECKING, NamedTuple
 
 if TYPE_CHECKING:
     from airflow.models import DagRun
-    from airflow.sdk.definitions.asset import AssetNameRef, AssetUniqueKey, 
AssetUriRef
-    from airflow.utils.state import DagRunState
 
+# When _AIRFLOW__AS_LIBRARY is set, airflow.sdk may not be installed
+# In that case, we define fallback exception classes
+if os.environ.get("_AIRFLOW__AS_LIBRARY"):
+    try:
+        from airflow.sdk.exceptions import AirflowException, 
AirflowNotFoundException
+    except ImportError:
+        # Fallback exception classes when airflow.sdk is not installed
+        class AirflowException(RuntimeError):  # type: ignore[no-redef]
+            """Base exception for Airflow errors."""
 
-class AirflowException(Exception):
-    """
-    Base class for all Airflow's errors.
+            pass
 
-    Each custom exception should be derived from this class.
-    """
+        class AirflowNotFoundException(AirflowException):  # type: 
ignore[no-redef]
+            """Raise when a requested object is not found."""
 
-    status_code = HTTPStatus.INTERNAL_SERVER_ERROR
+            pass
+else:
+    from airflow.sdk.exceptions import AirflowException, 
AirflowNotFoundException
 
-    def serialize(self):
-        cls = self.__class__
-        return f"{cls.__module__}.{cls.__name__}", (str(self),), {}
+
+class TaskNotFound(AirflowException):
+    """Raise when a Task is not available in the system."""

Review Comment:
   There are important usages of it in core so I had to duplicate it.



-- 
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]

Reply via email to