diff --git a/airflow-core/src/airflow/models/taskinstance.py b/airflow-core/src/airflow/models/taskinstance.py index 0fb9e4e88d9e9..85b438ca0e61a 100644 --- a/airflow-core/src/airflow/models/taskinstance.py +++ b/airflow-core/src/airflow/models/taskinstance.py @@ -1005,7 +1005,10 @@ def get_dagrun(self, session: Session = NEW_SESSION) -> DagRun: :return: DagRun """ info: Any = inspect(self) - if info.attrs.dag_run.loaded_value is not NO_VALUE: + # If dag_run is loaded and not None, return it. + # In early lifecycle phases (e.g. task_instance_mutation_hook), + # dag_run may be marked as loaded but still be None. + if info.attrs.dag_run.loaded_value is not NO_VALUE and self.dag_run is not None: if getattr(self, "task", None) is not None: if TYPE_CHECKING: assert self.task