Skip to content

Commit c717d12

Browse files
authored
Add __repr__ for DagTag so tags display properly in /dagmodel/show (apache#8719)
1 parent 8d6f1aa commit c717d12

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

airflow/models/dag.py

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

1688+
def __repr__(self):
1689+
return self.name
1690+
16881691

16891692
class DagModel(Base):
16901693

tests/models/test_dag.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,15 @@ def test_following_previous_schedule_daily_dag_cet_to_cest(self):
646646
self.assertEqual(prev_local.isoformat(), "2018-03-24T03:00:00+01:00")
647647
self.assertEqual(prev.isoformat(), "2018-03-24T02:00:00+00:00")
648648

649+
def test_dagtag_repr(self):
650+
clear_db_dags()
651+
dag = DAG('dag-test-dagtag', start_date=DEFAULT_DATE, tags=['tag-1', 'tag-2'])
652+
dag.sync_to_db()
653+
with create_session() as session:
654+
self.assertEqual({'tag-1', 'tag-2'},
655+
{repr(t) for t in session.query(DagTag).filter(
656+
DagTag.dag_id == 'dag-test-dagtag').all()})
657+
649658
def test_bulk_sync_to_db(self):
650659
clear_db_dags()
651660
dags = [

0 commit comments

Comments
 (0)