Home > Back-end >  DAG import error because ModuleNotFoundError
DAG import error because ModuleNotFoundError

Time:03-30

I recently upgraded from Airflow 1.10.15 to 2.2.4. Installed using sudo. Upgraded the DB after the upgrade. Airflow is running but there are import errors.

I have multiple DAGs with the line from airflow.operators.mssql_operator import MsSqlOperator but I am getting the following error once the scheduler and webserver are up:

Broken DAG: [/opt/airflow/dags/admissions.py] Traceback (most recent call last):
  File "/opt/airflow/dags/admissions.py", line 7, in <module>
    from airflow.operators.mssql_operator import MsSqlOperator
  File "/usr/local/lib/python3.6/dist-packages/airflow/operators/mssql_operator.py", line 22, in <module>
    from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator  # noqa
ModuleNotFoundError: No module named 'airflow.providers.microsoft.mssql.operators'

Additional information about providers:

apache-airflow-providers-ftp             | 2.1.0
apache-airflow-providers-http            | 2.1.0
apache-airflow-providers-imap            | 2.2.1
apache-airflow-providers-microsoft-mssql | 2.1.1
apache-airflow-providers-odbc            | 2.0.2
apache-airflow-providers-sqlite          | 2.1.1

How do I resolve this?

CodePudding user response:

It seems like you do have the correct provider's package (apache-airflow-providers-microsoft-mssql)

But, you are using the "old form" import instead of the new one

Please try to change
from airflow.operators.mssql_operator import MsSqlOperator
to
from airflow.providers.microsoft.mssql.operators.mssql import MsSqlOperator

Some links to API reference and small tutorial:
https://airflow.apache.org/docs/apache-airflow-providers-microsoft-mssql/stable/_api/airflow/providers/microsoft/mssql/operators/mssql/index.html#module-airflow.providers.microsoft.mssql.operators.mssql

https://airflow.apache.org/docs/apache-airflow-providers-microsoft-mssql/stable/operators.html#howto-operator-mssqloperator

  • Related