Skip to content

Commit 2f32df7

Browse files
authored
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
1 parent 178dee9 commit 2f32df7

1 file changed

Lines changed: 16 additions & 21 deletions

File tree

‎airflow/providers_manager.py‎

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,23 @@ def _add_hook(self, hook_class_name: str, provider_package: str) -> None:
280280
if field_behaviours:
281281
self._add_customized_fields(provider_package, hook_class, field_behaviours)
282282

283+
except ImportError as e: # noqa pylint: disable=broad-except
284+
# When there is an ImportError we turn it into debug warnings as this is
285+
# an expected case when only some providers are installed
286+
log.debug(
287+
"Exception when importing '%s' from '%s' package: %s",
288+
hook_class_name,
289+
provider_package,
290+
e,
291+
)
292+
return
283293
except Exception as e: # noqa pylint: disable=broad-except
284-
if os.environ.get("AIRFLOW_INSTALLATION_METHOD") != ".":
285-
# print providers manager warning when airflow is not installed from sources in the
286-
# production image
287-
log.warning(
288-
"Exception when importing '%s' from '%s' package: %s",
289-
hook_class_name,
290-
provider_package,
291-
e,
292-
)
293-
else:
294-
# This is special case - when airflow is installed from sources in production
295-
# image, AIRFLOW_INSTALLATION_METHOD is set to ".". In this case we know that there
296-
# Will be some warnings generated by ProviderManager, when it tries to import providers
297-
# With missing dependencies, therefore we are turning such warnings into debug message
298-
# so that we do not pollute logs.
299-
log.debug(
300-
"Exception when importing '%s' from '%s' package: %s",
301-
hook_class_name,
302-
provider_package,
303-
e,
304-
)
294+
log.warning(
295+
"Exception when importing '%s' from '%s' package: %s",
296+
hook_class_name,
297+
provider_package,
298+
e,
299+
)
305300
return
306301

307302
conn_type: str = self._get_attr(hook_class, 'conn_type')

0 commit comments

Comments
 (0)