I am new to python and I am having issues with my Airflow DAG which is importing modules inside my package.
Broken DAG: [/opt/airflow/dags/foo_export/util.py] Traceback (most recent call last): File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/opt/airflow/dags/foo_export/util.py", line 12, in <module> from .constants import ERROR_LOG ImportError: attempted relative import with no known parent package
I am using Python 3.9.18.
My Project/DAG Directory:
airflow
├── dags
│ ├── foo_export
│ ├── __init__.py
│ ├── util.py
│ └── config.py
│ └── export.py
│ └── dags.py
│ └── constants.py
├── airflow.cfg
├── logs
├── plugins
Snippet of the util.py:
import io
import logging
from contextlib import contextmanager
from datetime import datetime
from airflow.models import TaskInstance
from .constants import ERROR_LOG, PUBLICATION_DATE
....
Snippet of constants.py:
PUBLICATION_DATE = "publication_date"
ERROR_LOG = "error_log"
Strangely: This module worked on Airflow v.2.2.2 before without breaking any DAG this issue happens only after the update to v.2.7.2
According to https://airflow.apache.org/docs/apache-airflow/2.7.2/installation/prerequisites.html I am using a Python version which was also tested already.
In Modules Management docs section it says:
In your case you - as
dags
folder is under PYTHONPATH should have: