This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new e262c9e2d88 Fix/expose taskinstance api 60478 (#61568)
e262c9e2d88 is described below
commit e262c9e2d889ddce56dd6aacf1041540254fe0b6
Author: Subham <[email protected]>
AuthorDate: Wed Mar 4 02:54:38 2026 +0530
Fix/expose taskinstance api 60478 (#61568)
* Expose TaskInstance in Task SDK public API (#60478)
* Fix CI tests: add types to ignore list and TaskInstance to docs
* Expose TaskInstance as class and update docs inventory
* Fix Task SDK documentation inventory for TaskInstance
* Revert "Fix Task SDK documentation inventory for TaskInstance"
This reverts commit 09d3863cd636d171c6da1f79683e294bc5dd9259.
* Fix Task SDK documentation inventory for TaskInstance
---
task-sdk/docs/api.rst | 4 +++-
task-sdk/src/airflow/sdk/__init__.py | 3 +++
task-sdk/src/airflow/sdk/types.py | 12 ++++++++++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/task-sdk/docs/api.rst b/task-sdk/docs/api.rst
index 642cff1e34a..6b400e50448 100644
--- a/task-sdk/docs/api.rst
+++ b/task-sdk/docs/api.rst
@@ -123,6 +123,8 @@ Tasks & Operators
-----------------
.. autoapiclass:: airflow.sdk.TaskGroup
+.. autoclass:: airflow.sdk.TaskInstance
+
.. autoapiclass:: airflow.sdk.XComArg
.. autoapifunction:: airflow.sdk.literal
@@ -244,7 +246,7 @@ Everything else
.. autoapimodule:: airflow.sdk
:members:
:special-members: __version__
- :exclude-members: BaseAsyncOperator, BaseOperator, DAG, dag, asset, Asset,
AssetAlias, AssetAll, AssetAny, AssetWatcher, TaskGroup, XComArg,
get_current_context, get_parsing_context
+ :exclude-members: BaseAsyncOperator, BaseOperator, DAG, dag, asset, Asset,
AssetAlias, AssetAll, AssetAny, AssetWatcher, TaskGroup, TaskInstance, XComArg,
get_current_context, get_parsing_context
:undoc-members:
:imported-members:
:no-index:
diff --git a/task-sdk/src/airflow/sdk/__init__.py
b/task-sdk/src/airflow/sdk/__init__.py
index 22c12e74415..1259870bdbf 100644
--- a/task-sdk/src/airflow/sdk/__init__.py
+++ b/task-sdk/src/airflow/sdk/__init__.py
@@ -65,6 +65,7 @@ __all__ = [
"SkipMixin",
"SyncCallback",
"TaskGroup",
+ "TaskInstance",
"TaskInstanceState",
"Trace",
"TriggerRule",
@@ -151,6 +152,7 @@ if TYPE_CHECKING:
from airflow.sdk.execution_time import macros
from airflow.sdk.io.path import ObjectStoragePath
from airflow.sdk.observability.trace import Trace
+ from airflow.sdk.types import TaskInstance
conf: AirflowSDKConfigParser
@@ -201,6 +203,7 @@ __lazy_imports: dict[str, str] = {
"SkipMixin": ".bases.skipmixin",
"SyncCallback": ".definitions.callback",
"TaskGroup": ".definitions.taskgroup",
+ "TaskInstance": ".types",
"TaskInstanceState": ".api.datamodels._generated",
"Trace": ".observability.trace",
"TriggerRule": ".api.datamodels._generated",
diff --git a/task-sdk/src/airflow/sdk/types.py
b/task-sdk/src/airflow/sdk/types.py
index 3477c05b491..71c24474806 100644
--- a/task-sdk/src/airflow/sdk/types.py
+++ b/task-sdk/src/airflow/sdk/types.py
@@ -25,6 +25,8 @@ from airflow.sdk.api.datamodels._generated import WeightRule
from airflow.sdk.bases.xcom import BaseXCom
from airflow.sdk.definitions._internal.types import NOTSET, ArgNotSet
+__all__ = ["TaskInstance", "TaskInstanceKey"]
+
if TYPE_CHECKING:
from collections.abc import Iterator
@@ -182,6 +184,16 @@ class RuntimeTaskInstanceProtocol(Protocol):
def get_dagrun_state(dag_id: str, run_id: str) -> str: ...
+# Public alias for RuntimeTaskInstanceProtocol
+class TaskInstance(RuntimeTaskInstanceProtocol):
+ """
+ Protocol for TaskInstance available during runtime.
+
+ This class provides the interface for interacting with TaskInstance
attributes
+ and methods (like xcom_pull/push) within the Task SDK.
+ """
+
+
class OutletEventAccessorProtocol(Protocol):
"""Protocol for managing access to a specific outlet event accessor."""