Skip to content

ModuleNotFoundExceptions not matched as optional features #23823

Description

@ianbuss

Apache Airflow version

2.3.0 (latest released)

What happened

The providers_manager.py logs an import warning with stack trace (see example) for optional provider features instead of an info message noting the optional feature is disabled. Sample message:

[2022-05-19 21:46:53,065] {providers_manager.py:223} WARNING - Exception when importing 'airflow.providers.google.cloud.hooks.compute_ssh.ComputeEngineSSHHook' from 'apache-airflow-providers-google' package
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/airflow/providers_manager.py", line 257, in _sanity_check
    imported_class = import_string(class_name)
  File "/usr/local/lib/python3.9/site-packages/airflow/utils/module_loading.py", line 32, in import_string
    module = import_module(module_path)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/airflow/providers/google/cloud/hooks/compute_ssh.py", line 23, in <module>
    import paramiko
ModuleNotFoundError: No module named 'paramiko'

What you think should happen instead

There is explicit code for catching ModuleNotFoundExceptions so these import errors should be logged as info messages like:

[2022-05-20 08:18:54,680] {providers_manager.py:215} INFO - Optional provider feature disabled when importing 'airflow.providers.google.cloud.hooks.compute_ssh.ComputeEngineSSHHook' from 'apache-airflow-providers-google' package

How to reproduce

Install the google provider but do not install the ssh submodule (or alternatively the mysql module). Various airflow components will produce the above warning logs.

Operating System

Debian bullseye

Versions of Apache Airflow Providers

No response

Deployment

Other Docker-based deployment

Deployment details

No response

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions