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 2021/08/16 16:09:58 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #17625: Adds secret backend and logging information to provider yaml

mik-laj commented on a change in pull request #17625:
URL: https://github.com/apache/airflow/pull/17625#discussion_r689670688



##########
File path: airflow/providers_manager.py
##########
@@ -61,6 +62,36 @@ def _create_customized_form_field_behaviours_schema_validator():
     return validator
 
 
+def _sanity_check(provider_package: str, class_name: str) -> bool:
+    """
+    Performs sanity check on provider classes.
+    For apache-airflow providers - it checks if it starts with appropriate package. For all providers
+    it tries to import the provider - checking that there are no exceptions during importing.
+    """
+    if provider_package.startswith("apache-airflow"):
+        provider_path = provider_package[len("apache-") :].replace("-", ".")
+        if not class_name.startswith(provider_path):
+            log.warning(
+                "Sanity check failed when importing '%s' from '%s' package. It should start with '%s'",
+                class_name,
+                provider_package,
+                provider_path,
+            )
+            return False
+    try:
+        module, class_name = class_name.rsplit('.', maxsplit=1)
+        getattr(importlib.import_module(module), class_name)

Review comment:
       Can we use [`import_string`](https://github.com/apache/airflow/blob/main/airflow/utils/module_loading.py#L22) here?




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