Issue with Importing and Displaying DAG Code in Apache Airflow UI when use a subproject

99 views Asked by At

I am facing a problem when importing DAGs into Apache Airflow using a script, as I am not able to see the DAG code in the Airflow UI. It only displays the code used for importation. Here's the code I'm using:

import os
from airflow.models import DagBag
import sys

dags_dirs = [
    '/opt/airflow/projetos/basevinculos_py',
    '/opt/airflow/projetos/pdi_consulta'
]

for dir in dags_dirs:
    sys.path.append(os.path.expanduser(dir))

for dir in dags_dirs:
    dag_bag = DagBag(os.path.expanduser(dir))

    if dag_bag:
        for dag_id, dag in dag_bag.dags.items():
            globals()[dag_id] = dag

I have verified that the DAGs are successfully imported into Airflow, but the Airflow UI does not display the code for the imported DAGs. I've ensured that the DAG definition files are correctly formatted and contain the necessary DAG structure. I'm using Apache Airflow 2.7.2enter image description here

The Graph tab shows correctly the tasks flow correctly, but unfortunately in the code tab shows me only the code that I am using to deal with the DagBag.

0

There are 0 answers