Skip to content

Commit 5bfad70

Browse files
XD-DENGChris Fei
authored andcommitted
Add __repr__ for DagTag so tags display properly in /dagmodel/show (apache#8719)
(cherry picked from commit c717d12)
1 parent a2e2334 commit 5bfad70

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

airflow/models/dag.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,9 @@ class DagTag(Base):
17111711
name = Column(String(100), primary_key=True)
17121712
dag_id = Column(String(ID_LEN), ForeignKey('dag.dag_id'), primary_key=True)
17131713

1714+
def __repr__(self):
1715+
return self.name
1716+
17141717

17151718
class DagModel(Base):
17161719

tests/models/test_dag.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from airflow import models, settings
3737
from airflow.configuration import conf
3838
from airflow.exceptions import AirflowException, AirflowDagCycleException
39-
from airflow.models import DAG, DagModel, TaskInstance as TI
39+
from airflow.models import DAG, DagModel, DagTag, TaskInstance as TI
4040
from airflow.operators.bash_operator import BashOperator
4141
from airflow.operators.dummy_operator import DummyOperator
4242
from airflow.operators.subdag_operator import SubDagOperator
@@ -46,6 +46,7 @@
4646
from airflow.utils.state import State
4747
from airflow.utils.weight_rule import WeightRule
4848
from tests.models import DEFAULT_DATE
49+
from tests.test_utils.db import clear_db_dags
4950

5051

5152
class DagTest(unittest.TestCase):
@@ -657,6 +658,15 @@ def test_following_previous_schedule_daily_dag_CET_to_CEST(self):
657658
self.assertEqual(prev_local.isoformat(), "2018-03-24T03:00:00+01:00")
658659
self.assertEqual(prev.isoformat(), "2018-03-24T02:00:00+00:00")
659660

661+
def test_dagtag_repr(self):
662+
clear_db_dags()
663+
dag = DAG('dag-test-dagtag', start_date=DEFAULT_DATE, tags=['tag-1', 'tag-2'])
664+
dag.sync_to_db()
665+
with create_session() as session:
666+
self.assertEqual({'tag-1', 'tag-2'},
667+
{repr(t) for t in session.query(DagTag).filter(
668+
DagTag.dag_id == 'dag-test-dagtag').all()})
669+
660670
@patch('airflow.models.dag.timezone.utcnow')
661671
def test_sync_to_db(self, mock_now):
662672
dag = DAG(

0 commit comments

Comments
 (0)