Daniel is completely right. You should not use relative imports.
Airflow does import files in a different way than regular import, for
multiple reasons. "Don't use relative imports" is even very explicitly
stated (with examples) in the best practices we have for module
management (for precisely this reason):

https://airflow.apache.org/docs/apache-airflow/stable/modules_management.html?highlight=module%20management#best-practices-for-module-loading

BTW: I recommend you follow all the advice from there.

J.


On Wed, Mar 23, 2022 at 5:07 AM Daniel Standish
<[email protected]> wrote:
>
> I am not sure why it works in airflow (perhaps dags are parsed in distinct 
> processes???).  But, thinking of how you might fix this.... it seems you are 
> doing relative imports.  Maybe if you stop doing that, that would be enough.  
> So instead of importing `from config import value` you could do `from 
> dags.my_dir1.my_dir2.config import value`.  Then you wouldn't need to muck 
> with the python path either.
>

Reply via email to