@@ -1475,6 +1475,24 @@ class DagModel(Base, LoggingMixin):
1475
1475
def __repr__ (self ):
1476
1476
return "<DAG: {self.dag_id}>" .format (self = self )
1477
1477
1478
+ def get_local_fileloc (self ):
1479
+ # TODO: [CX-16591] Resolve this in upstream by storing relative path in db (config driven)
1480
+ try :
1481
+ # Fix for DAGs that are manually triggered in the UI, as the DAG path in the DB is
1482
+ # stored by the scheduler which has a different path than the webserver due to absolute
1483
+ # paths in aurora including randomly generated job-specific directories. Due to this
1484
+ # the path the webserver uses when it tries to trigger a DAG does not match the
1485
+ # existing scheduler path and the DAG can not be found.
1486
+ # Also, fix for render code on UI by changing "/code" in views.py
1487
+ path_regex = "airflow_scheduler-.-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[" \
1488
+ "0-9a-f]{12}/runs/.*/sandbox/airflow_home"
1489
+ path_split = re .split (path_regex , self .fileloc )[1 ]
1490
+ return os .environ .get ("AIRFLOW_HOME" ) + path_split
1491
+ except IndexError :
1492
+ self .log .info ("No airflow_home in path: " + self .fileloc )
1493
+
1494
+ return self .fileloc
1495
+
1478
1496
@property
1479
1497
def timezone (self ):
1480
1498
return settings .TIMEZONE
@@ -1505,21 +1523,7 @@ def safe_dag_id(self):
1505
1523
return self .dag_id .replace ('.' , '__dot__' )
1506
1524
1507
1525
def get_dag (self ):
1508
- # TODO: [CX-16591] Resolve this in upstream by storing relative path in db (config driven)
1509
- try :
1510
- # Fix for DAGs that are manually triggered in the UI, as the DAG path in the DB is
1511
- # stored by the scheduler which has a different path than the webserver due to absolute
1512
- # paths in aurora including randomly generated job-specific directories. Due to this
1513
- # the path the webserver uses when it tries to trigger a DAG does not match the
1514
- # existing scheduler path and the DAG can not be found.
1515
- path_regex = "airflow_scheduler-.-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[" \
1516
- "0-9a-f]{12}/runs/.*/sandbox/airflow_home"
1517
- path_split = re .split (path_regex , self .fileloc )[1 ]
1518
- self .fileloc = os .environ .get ("AIRFLOW_HOME" ) + path_split
1519
- except IndexError :
1520
- self .log .info ("No airflow_home in path: " + self .fileloc )
1521
-
1522
- return DagBag (dag_folder = self .fileloc ).get_dag (self .dag_id )
1526
+ return DagBag (dag_folder = self .get_local_fileloc ()).get_dag (self .dag_id )
1523
1527
1524
1528
@provide_session
1525
1529
def create_dagrun (self ,
0 commit comments