I followed the tutorial about plugins.
I looked online also and find : Can't import Airflow plugins
But the top answer doesn't help me either.
Here a simplifed version of my project :
airflow_home
├── dags
│ └── etl.py
└── plugins
├── __init__.py
└── operators
├── __init__.py
└── dump_file.py
plugins/operators/dump_file.py
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
class DumpCsvFileToPostgres(BaseOperator):
[...]
# plugins/__init__.py
from airflow.plugins_manager import AirflowPlugin
from plugins.operators.dump_file import DumpCsvFileToPostgres
# Defining the plugin class
class CustomPlugin(AirflowPlugin):
name = "custom_plugin"
operators = [
DumpCsvFileToPostgres
]
helpers = []
dags/etl.py
# tried
# from airflow.operators import DumpCsvFileToPostgres
# from airflow.operators.custom_plugin import DumpCsvFileToPostgres
from custom_plugin import DumpCsvFileToPostgres
[...]
I still get
Broken DAG: [/root/airflow/dags/etl_dag.py] No module named 'custom_plugin'
My webserver and scheduler are running with a docker-compose
version: '3.7'
services:
[...]
webserver:
image: godatadriven/airflow:latest
environment:
- AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://${POSTGRES_USER:-airflow}:${POSTGRES_PASSWORD:-airflow}@postgres:5432/${POSTGRES_DB:-airflow}
- AIRFLOW__CORE__EXECUTOR=LocalExecutor
- WAIT_FOR=postgres:5432
depends_on:
- postgres
volumes:
- ./dags:/root/airflow/dags
- ./plugins:/root/airflow/plugins
- ./logs:/root/airflow/logs
- ./environment.yml:/dependencies/environment.yml
ports:
- "8080:8080"
command: upgradedb_webserver
scheduler:
image: godatadriven/airflow:latest
environment:
- AIRFLOW__CORE__SQL_ALCHEMY_CONN=postgresql+psycopg2://${POSTGRES_USER:-airflow}:${POSTGRES_PASSWORD:-airflow}@postgres:5432/${POSTGRES_DB:-airflow}
- AIRFLOW__CORE__EXECUTOR=LocalExecutor
- WAIT_FOR=webserver:8080
depends_on:
- webserver
volumes:
- ./dags:/root/airflow/dags
- ./plugins:/root/airflow/plugins
- ./logs:/root/airflow/logs
- ./environment.yml:/dependencies/environment.yml
- ./dataset/Iowa_Liquor_Sales.csv:/root/airflow/dataset/dataset.csv
command: scheduler