<<airflow.providers.jdbc>> module named error in Airflow2.x

  airflow, airflow-2.x, docker

I am using airflow 2.0. I am trying to connect to redshift, using docker container on mac.

Here is my dag.py:

from airflow import DAG
from datetime import datetime,timedelta


from airflow.operators.bash import BashOperator
from airflow.operators.python import PythonOperator,BranchPythonOperator
from airflow.providers.jdbc.hooks.jdbc import JdbcHook



#Creating JDBC connection using Conn ID
JdbcConn = JdbcHook(jdbc_conn_id='Redshift_conn')
def getconnection():
    JdbcConn.get_connection('Redshift')
    print("connected")

default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': airflow.utils.dates.days_ago(2),
    'email': ['[email protected]'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5)
}

with DAG(
    dag_id="redshift",default_args=default_args ,schedule_interval="@daily",
    catchup=False) as dag:

    t1 = PythonOperator(
    task_id='getconnection',
    python_callable=getconnection
)

Here is definition of connection
enter image description here

Airflow UI is showing this error and I don’t know how to get rid of it.

Broken DAG: [/opt/airflow/dags/redshift.py] Traceback (most recent
call last): File "", line 219, in
_call_with_frames_removed File "/opt/airflow/dags/redshift.py", line 7, in
from airflow.providers.jdbc.hooks.jdbc import JdbcHook ModuleNotFoundError: No module named ‘airflow.providers.jdbc’

Any help will be appreciated!!

Source: Docker Questions

LEAVE A COMMENT