Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,13 @@ def sync_to_db(self, sync_time=None, session=None):
"""
self.bulk_sync_to_db([self], sync_time, session)

def get_default_view(self):
"""This is only there for backward compatible jinja2 templates"""
if self.default_view is None:
return conf.get('webserver', 'dag_default_view').lower()
else:
return self.default_view
Comment on lines +1624 to +1629
Copy link
Copy Markdown
Member

@mik-laj mik-laj Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_default_view(self):
"""This is only there for backward compatible jinja2 templates"""
if self.default_view is None:
return conf.get('webserver', 'dag_default_view').lower()
else:
return self.default_view
@property
def default_view(self):
"""This is only there for backward compatible jinja2 templates"""
if self._default_view is None:
return conf.get('webserver', 'dag_default_view').lower()
else:
return self._default_view
@default_view.setter
def default_view(self, value):
self._default_view= value

This way we won't have two similar public attributes of default_view property, get_default_view method.

Copy link
Copy Markdown
Member Author

@kaxil kaxil Sep 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept it there for parity between Dag and DagModel, otherwise dag.html and dags.html might use or the other depending on if we are using Dag or DagModel

The other option is to create a Database migration to fill all the null values, WDYT? @mik-laj

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mik-laj Any comments?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey. Now I understand the whole change. It looks good.


@staticmethod
@provide_session
def deactivate_unknown_dags(active_dag_ids, session=None):
Expand Down Expand Up @@ -1820,6 +1827,14 @@ def get_paused_dag_ids(dag_ids: List[str], session: Session = None) -> Set[str]:
paused_dag_ids = set(paused_dag_id for paused_dag_id, in paused_dag_ids)
return paused_dag_ids

def get_default_view(self) -> str:
"""
Get the Default DAG View, returns the default config value if DagModel does not
have a value
"""
# This is for backwards-compatibility with old dags that don't have None as default_view
return self.default_view or conf.get('webserver', 'dag_default_view').lower()

@property
def safe_dag_id(self):
return self.dag_id.replace('.', '__dot__')
Expand Down
4 changes: 2 additions & 2 deletions airflow/www/templates/airflow/dag.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h4 class="pull-right">
</div>
<div class="col-md-2">
<div class="btn-group pull-right">
<a href="{{ url_for('Airflow.trigger', dag_id=dag.dag_id, origin=url_for('Airflow.' + dag.default_view, dag_id=dag.dag_id)) }}" title="Trigger DAG" aria-label="Trigger DAG" class="btn btn-default">
<a href="{{ url_for('Airflow.trigger', dag_id=dag.dag_id, origin=url_for('Airflow.' + dag.get_default_view(), dag_id=dag.dag_id)) }}" title="Trigger DAG" aria-label="Trigger DAG" class="btn btn-default">
<span class="glyphicon glyphicon-play" aria-hidden="true"></span>
</a>
<a href="{{ url_for('Airflow.refresh', dag_id=dag.dag_id) }}" title="Refresh DAG" aria-label="Refresh DAG" onclick="postAsForm(this.href); return false" class="btn btn-default">
Expand Down Expand Up @@ -125,7 +125,7 @@ <h4 class="modal-title" id="myModalLabel">
</div>
<div class="modal-body">
<div id="div_btn_subdag">
<a id="btn_subdag" type="button" class="btn btn-primary" data-base-url="{{ url_for('Airflow.' + dag.default_view) }}">
<a id="btn_subdag" type="button" class="btn btn-primary" data-base-url="{{ url_for('Airflow.' + dag.get_default_view()) }}">
Zoom into Sub DAG
</a>
<hr/>
Expand Down
2 changes: 1 addition & 1 deletion airflow/www/templates/airflow/dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h2>DAGs</h2>
<!-- Column 3: Name -->
<td>
<span>
<a href="{{ url_for('Airflow.'+ dag.default_view, dag_id=dag.dag_id) }}"
<a href="{{ url_for('Airflow.'+ dag.get_default_view(), dag_id=dag.dag_id) }}"
title="{{ dag.description[0:80] + '…' if dag.description and dag.description|length > 80 else dag.description|default('', true) }}">
{{ dag.dag_id }}
</a>
Expand Down
11 changes: 11 additions & 0 deletions tests/models/test_dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class TestDag(unittest.TestCase):

def setUp(self) -> None:
clear_db_runs()
clear_db_dags()

def tearDown(self) -> None:
clear_db_runs()
clear_db_dags()

@staticmethod
def _clean_up(dag_id: str):
Expand Down Expand Up @@ -895,6 +897,15 @@ def test_new_dag_is_paused_upon_creation(self):
self.assertTrue(orm_dag.is_paused)
session.close()

def test_existing_dag_default_view(self):

with create_session() as session:
session.add(DagModel(dag_id='dag_default_view_old', default_view=None))
session.commit()
orm_dag = session.query(DagModel).filter(DagModel.dag_id == 'dag_default_view_old').one()
self.assertIsNone(orm_dag.default_view)
self.assertEqual(orm_dag.get_default_view(), conf.get('webserver', 'dag_default_view').lower())

def test_dag_is_deactivated_upon_dagfile_deletion(self):
dag_id = 'old_existing_dag'
dag_fileloc = "/usr/local/airflow/dags/non_existing_path.py"
Expand Down