You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/03/20 01:05:14 UTC

[airflow] branch master updated: Turn provider's import warnings into debug logs (#14903)

This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f32df7  Turn provider's import warnings into debug logs (#14903)
2f32df7 is described below

commit 2f32df7b711cf63d18efd5e0023b22a79040cc86
Author: Jarek Potiuk <ja...@potiuk.com>
AuthorDate: Sat Mar 20 02:04:52 2021 +0100

    Turn provider's import warnings into debug logs (#14903)
    
    When only some providers are installed, cross-dependencies between
    the providers might cause import erors. Those import errors are
    repeated in webserver as it is reloaded every 30 seconds.
    
    Since "only some providers" case is valid, it should not generate
    warrnings if it is an ImportError. Those warnings are now
    turned into debug messages.
    
    Fixes: #14286
---
 airflow/providers_manager.py | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/airflow/providers_manager.py b/airflow/providers_manager.py
index 8ba6bf2..420135b 100644
--- a/airflow/providers_manager.py
+++ b/airflow/providers_manager.py
@@ -280,28 +280,23 @@ class ProvidersManager:
                 if field_behaviours:
                     self._add_customized_fields(provider_package, hook_class, field_behaviours)
 
+        except ImportError as e:  # noqa pylint: disable=broad-except
+            # When there is an ImportError we turn it into debug warnings as this is
+            # an expected case when only some providers are installed
+            log.debug(
+                "Exception when importing '%s' from '%s' package: %s",
+                hook_class_name,
+                provider_package,
+                e,
+            )
+            return
         except Exception as e:  # noqa pylint: disable=broad-except
-            if os.environ.get("AIRFLOW_INSTALLATION_METHOD") != ".":
-                # print providers manager warning when airflow is not installed from sources in the
-                # production image
-                log.warning(
-                    "Exception when importing '%s' from '%s' package: %s",
-                    hook_class_name,
-                    provider_package,
-                    e,
-                )
-            else:
-                # This is special case - when airflow is installed from sources in production
-                # image, AIRFLOW_INSTALLATION_METHOD is set to ".". In this case we know that there
-                # Will be some warnings generated by ProviderManager, when it tries to import providers
-                # With missing dependencies, therefore we are turning such warnings into debug message
-                # so that we do not pollute logs.
-                log.debug(
-                    "Exception when importing '%s' from '%s' package: %s",
-                    hook_class_name,
-                    provider_package,
-                    e,
-                )
+            log.warning(
+                "Exception when importing '%s' from '%s' package: %s",
+                hook_class_name,
+                provider_package,
+                e,
+            )
             return
 
         conn_type: str = self._get_attr(hook_class, 'conn_type')