This is an automated email from the ASF dual-hosted git repository. kaxilnaik pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit c99194a6d4bc4327061257aa249e9d50aebfaf1e Author: Xiaodong DENG <xd_d...@hotmail.com> AuthorDate: Tue May 5 20:32:18 2020 +0200 Add __repr__ for DagTag so tags display properly in /dagmodel/show (#8719) (cherry picked from commit c717d12f47c604082afc106b7a4a1f71d91f73e2) --- airflow/models/dag.py | 3 +++ tests/models/test_dag.py | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/airflow/models/dag.py b/airflow/models/dag.py index e24c164..94c6d2e 100644 --- a/airflow/models/dag.py +++ b/airflow/models/dag.py @@ -1711,6 +1711,9 @@ class DagTag(Base): name = Column(String(100), primary_key=True) dag_id = Column(String(ID_LEN), ForeignKey('dag.dag_id'), primary_key=True) + def __repr__(self): + return self.name + class DagModel(Base): diff --git a/tests/models/test_dag.py b/tests/models/test_dag.py index 5d9d05d..b711a8b 100644 --- a/tests/models/test_dag.py +++ b/tests/models/test_dag.py @@ -36,7 +36,7 @@ from mock import patch from airflow import models, settings from airflow.configuration import conf from airflow.exceptions import AirflowException, AirflowDagCycleException -from airflow.models import DAG, DagModel, TaskInstance as TI +from airflow.models import DAG, DagModel, DagTag, TaskInstance as TI from airflow.operators.bash_operator import BashOperator from airflow.operators.dummy_operator import DummyOperator from airflow.operators.subdag_operator import SubDagOperator @@ -46,6 +46,7 @@ from airflow.utils.db import create_session from airflow.utils.state import State from airflow.utils.weight_rule import WeightRule from tests.models import DEFAULT_DATE +from tests.test_utils.db import clear_db_dags class DagTest(unittest.TestCase): @@ -657,6 +658,15 @@ class DagTest(unittest.TestCase): self.assertEqual(prev_local.isoformat(), "2018-03-24T03:00:00+01:00") self.assertEqual(prev.isoformat(), "2018-03-24T02:00:00+00:00") + def test_dagtag_repr(self): + clear_db_dags() + dag = DAG('dag-test-dagtag', start_date=DEFAULT_DATE, tags=['tag-1', 'tag-2']) + dag.sync_to_db() + with create_session() as session: + self.assertEqual({'tag-1', 'tag-2'}, + {repr(t) for t in session.query(DagTag).filter( + DagTag.dag_id == 'dag-test-dagtag').all()}) + @patch('airflow.models.dag.timezone.utcnow') def test_sync_to_db(self, mock_now): dag = DAG(