zorzigio opened a new issue #15572:
URL: https://github.com/apache/airflow/issues/15572


   **Apache Airflow version**: 2.0.2
   
   
   **Kubernetes version**:
   - Client Version: v1.17.4
   - Server Version: v1.18.14
   
   **Environment**:
   
   - **Cloud provider or hardware configuration**: Azure
   - **OS**: "Debian GNU/Linux 10 (buster)"
   - **Kernel**: Linux airflow2-webserver-96bfc89f7-qwk26 5.4.0-1043-azure 
#45~18.04.1-Ubuntu SMP Sat Mar 20 16:16:05 UTC 2021 x86_64 GNU/Linux
   
   **What happened**:
   
   My folder structure is the following
   
   ```bash
   /opt/airflow
   ├── dags
   │   ├── __init__.py
   │   ├── example_k8s
   │   │   └── test.py
   │   └── utils
   │       ├── defaults.py
   │       ├── __init__.py
   └── ...
   ```
   
   In `test.py` I am importing from `defaults.py` as follows
   
   ```python
   from utils.defaults import DEFAULT_ARGS, DEFAULT_NAMESPACE
   ```
   
   This raises an error in the UI
   
   ```bash
   Broken DAG: [/opt/airflow/dags/example_k8s/test.py] Traceback (most recent 
call last):
     File "<frozen importlib._bootstrap>", line 219, in 
_call_with_frames_removed
     File "/opt/airflow/dags/example_k8s/test.py", line 200, in <module>
       from utils.defaults import DEFAULT_ARGS, DEFAULT_NAMESPACE
   ModuleNotFoundError: No module named 'utils'
   ```
   
   Not sure why as the folder `/opt/airflow/dags` should be already included in 
the path (at least in the worker pod) as when I print `sys.path` from a 
`PythonOperator` I get
   
   ```bash
   ['/home/airflow/.local/bin', '/usr/local/lib/python36.zip', 
'/usr/local/lib/python3.6', '/usr/local/lib/python3.6/lib-dynload', 
'/home/airflow/.local/lib/python3.6/site-packages', 
'/usr/local/lib/python3.6/site-packages', '/opt/airflow/dags', 
'/opt/airflow/config', '/opt/airflow/plugins']
   ```
   
   and executing the command 
   
   ```bash
   python /opt/airflow/dags/example_k8s/test.py
   ```
   
   in the webserver does not raise any error.
   
   If I explicitly add `/opt/airflow/dags` to the system path in `test.py`
   
   ```python
   sys.path.insert(0, '/opt/airflow/dags/')
   ```
   
   the error in the UI is no longer reported and the DAG appears in the UI.
   
   **What you expected to happen**:
   
   The import to work even without explicitly adding the path to the system
   
   **How to reproduce it**:
   See above
   
   
   **Anything else we need to know**:
   
   Airflow has been installed using Helm
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to