xBis7 commented on code in PR #71737:
URL: https://github.com/apache/airflow/pull/71737#discussion_r4382035019


##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -163,14 +164,95 @@ def validate_loop_decision(stop: bool | None, 
region_index: int, group: Serializ
         raise InvalidLoopDecision("Fixed-count loop decision does not match 
its iteration limit")
 
 
+@dataclass(frozen=True, slots=True, eq=False)
+class FinishedTI:
+    """
+    Immutable view of a task instance in a terminal state.
+
+    Keeps the dag_run rescan lightweight and fast: scheduling only reads these 
columns
+    off finished task instances, so a fully instrumented TaskInstance per row 
is
+    unnecessary. ``task`` is attached from the serialized dag rather than the 
row.
+
+    ``eq=False`` keeps identity equality and ``__hash__`` mirrors the key 
hash, the same as
+    a TaskInstance.
+
+    Anything needing a full TaskInstance must re-fetch it (see 
``_ensure_type_task_instance``).
+    """
+
+    id: UUID
+    dag_id: str
+    run_id: str
+    task_id: str
+    region_id: UUID
+    region_index: int
+    dag_version_id: UUID | None
+    state: str | None
+    start_date: datetime | None
+    end_date: datetime | None
+    task: Operator | None = None
+
+    @property
+    def map_index(self) -> int:
+        """Mirror the ``TaskInstance.map_index`` synonym of 
``region_index``."""
+        return self.region_index
+
+    def __hash__(self) -> int:
+        return hash((self.task_id, self.dag_id, self.run_id, 
self.region_index))
+
+
+# Get the necessary columns from the FinishedTI fields so that the class stays
+# the single source of truth. For any needed change, add or remove a field 
there.
+FINISHED_TI_COLUMNS = tuple(getattr(TI, f.name) for f in fields(FinishedTI) if 
f.name != "task")
+
+
+class SchedulingTI(Protocol):

Review Comment:
   Yes, it's simpler this way. I moved it under `task_coordinates` and I also 
updated `_mapped_group_skip_decisions`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to