You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/01/26 07:08:46 UTC

[GitHub] [airflow] uranusjr commented on a change in pull request #21074: Add optional features in providers.

uranusjr commented on a change in pull request #21074:
URL: https://github.com/apache/airflow/pull/21074#discussion_r792358215



##########
File path: airflow/providers/google/leveldb/hooks/leveldb.py
##########
@@ -17,11 +17,24 @@
 """Hook for Level DB"""
 from typing import List, Optional
 
-import plyvel
-from plyvel import DB
-
-from airflow.exceptions import AirflowException
-from airflow.hooks.base import BaseHook
+try:
+    import plyvel
+    from plyvel import DB
+
+    from airflow.exceptions import AirflowException
+    from airflow.hooks.base import BaseHook
+
+except ImportError as e:
+    # Plyvel is an optional feature and if imports are missing, it should be silently ignored
+    # As of Airflow 2.3  and above the operator can throw OptionalProviderFeatureException
+    try:
+        from airflow.exceptions import AirflowOptionalProviderFeatureException
+    except ImportError:
+        # However, in order to keep backwards-compatibility with Airflow 2.1 and 2.2, if the
+        # 2.3 exception cannot be imported, the original ImportError should be raised.
+        # This try/except can be removed when the provider depends on Airflow >= 2.3.0
+        raise e

Review comment:
       Better to do `raise e from None` here to avoid the nested `ImportError` confusing the traceback.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org