Skip to content

Commit 22b20d6

Browse files
authored
Add logical_date to models using execution_date (#44283)
Airflow 3 renames all database columns from 'execution_date' to 'logical_date'. This backports the new name to 2.x so users can change their code accessing those fields to use the new name before upgrading to Airflow 3.
1 parent 846963d commit 22b20d6

File tree

7 files changed

+20
-0
lines changed

7 files changed

+20
-0
lines changed

airflow/models/log.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from airflow.utils.sqlalchemy import UtcDateTime
2727

2828
if TYPE_CHECKING:
29+
from datetime import datetime
30+
2931
from airflow.models.taskinstance import TaskInstance
3032
from airflow.models.taskinstancekey import TaskInstanceKey
3133

@@ -100,3 +102,7 @@ def __init__(
100102

101103
def __str__(self) -> str:
102104
return f"Log({self.event}, {self.task_id}, {self.owner}, {self.owner_display_name}, {self.extra})"
105+
106+
@property
107+
def logical_date(self) -> datetime:
108+
return self.execution_date

airflow/models/renderedtifields.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class RenderedTaskInstanceFields(TaskInstanceDependencies):
115115
)
116116

117117
execution_date = association_proxy("dag_run", "execution_date")
118+
logical_date = association_proxy("dag_run", "execution_date")
118119

119120
def __init__(self, ti: TaskInstance, render_templates=True, rendered_fields=None):
120121
self.dag_id = ti.dag_id

airflow/models/slamiss.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
1717
# under the License.
1818
from __future__ import annotations
1919

20+
from typing import TYPE_CHECKING
21+
2022
from sqlalchemy import Boolean, Column, Index, String, Text
2123

2224
from airflow.models.base import COLLATION_ARGS, ID_LEN, Base
2325
from airflow.utils.sqlalchemy import UtcDateTime
2426

27+
if TYPE_CHECKING:
28+
from datetime import datetime
29+
2530

2631
class SlaMiss(Base):
2732
"""
@@ -44,3 +49,7 @@ class SlaMiss(Base):
4449

4550
def __repr__(self):
4651
return str((self.dag_id, self.task_id, self.execution_date.isoformat()))
52+
53+
@property
54+
def logical_date(self) -> datetime:
55+
return self.execution_date

airflow/models/taskinstance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,7 @@ class TaskInstance(Base, LoggingMixin):
19021902
dag_run = relationship("DagRun", back_populates="task_instances", lazy="joined", innerjoin=True)
19031903
rendered_task_instance_fields = relationship("RenderedTaskInstanceFields", lazy="noload", uselist=False)
19041904
execution_date = association_proxy("dag_run", "execution_date")
1905+
logical_date = association_proxy("dag_run", "execution_date")
19051906
task_instance_note = relationship(
19061907
"TaskInstanceNote",
19071908
back_populates="task_instance",

airflow/models/taskreschedule.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class TaskReschedule(TaskInstanceDependencies):
8080
)
8181
dag_run = relationship("DagRun")
8282
execution_date = association_proxy("dag_run", "execution_date")
83+
logical_date = association_proxy("dag_run", "execution_date")
8384

8485
def __init__(
8586
self,

airflow/models/xcom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class BaseXCom(TaskInstanceDependencies, LoggingMixin):
119119
passive_deletes="all",
120120
)
121121
execution_date = association_proxy("dag_run", "execution_date")
122+
logical_date = association_proxy("dag_run", "execution_date")
122123

123124
@reconstructor
124125
def init_on_load(self):

scripts/ci/pre_commit/check_ti_vs_tis_attributes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def compare_attributes(path1, path2):
4848
"task_instance_note",
4949
"dag_run",
5050
"trigger",
51+
"execution_date",
5152
"logical_date",
5253
"triggerer_job",
5354
"note",

0 commit comments

Comments
 (0)