Skip to content

Commit c905ad0

Browse files
committed
docs: Update public interface documentation for Airflow 3.0+ for metadata direct access change
1 parent a041a2a commit c905ad0

File tree

4 files changed

+260
-64
lines changed

4 files changed

+260
-64
lines changed

airflow-core/docs/conf.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120

121121
PACKAGES_THAT_WE_SHOULD_ADD_TO_API_DOCS = {
122122
"hooks",
123-
"decorators",
124123
"example_dags",
125124
"executors",
126125
"operators",
@@ -140,15 +139,7 @@
140139

141140
MODELS_THAT_SHOULD_BE_INCLUDED_IN_API_DOCS: set[str] = {
142141
"baseoperator.py",
143-
"connection.py",
144-
"dag.py",
145-
"dagrun.py",
146-
"dagbag.py",
147142
"param.py",
148-
"taskinstance.py",
149-
"taskinstancekey.py",
150-
"variable.py",
151-
"xcom.py",
152143
}
153144

154145

airflow-core/docs/core-concepts/params.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If the user-supplied values don't pass validation, Airflow shows a warning inste
3232
DAG-level Params
3333
----------------
3434

35-
To add Params to a :class:`~airflow.models.dag.DAG`, initialize it with the ``params`` kwarg.
35+
To add Params to a :class:`~airflow.sdk.DAG`, initialize it with the ``params`` kwarg.
3636
Use a dictionary that maps Param names to either a :class:`~airflow.sdk.definitions.param.Param` or an object indicating the parameter's default value.
3737

3838
.. code-block::

airflow-core/docs/core-concepts/xcoms.rst

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ XComs (short for "cross-communications") are a mechanism that let :doc:`tasks` t
2525

2626
An XCom is identified by a ``key`` (essentially its name), as well as the ``task_id`` and ``dag_id`` it came from. They can have any serializable value (including objects that are decorated with ``@dataclass`` or ``@attr.define``, see :ref:`TaskFlow arguments <concepts:arbitrary-arguments>`:), but they are only designed for small amounts of data; do not use them to pass around large values, like dataframes.
2727

28+
.. versionchanged:: 3.0
29+
30+
In Airflow 3.0+, XCom operations should be performed through the Task Context using
31+
:func:`~airflow.sdk.get_current_context`. Direct database access is not possible.
32+
2833
XComs are explicitly "pushed" and "pulled" to/from their storage using the ``xcom_push`` and ``xcom_pull`` methods on Task Instances.
2934

3035
To push a value within a task called **"task-1"** that will be used by another task:
@@ -73,8 +78,27 @@ An example of pushing multiple XComs and pulling them individually:
7378
# Pulling entire xcom data from push_multiple task
7479
data = context["ti"].xcom_pull(task_ids="push_multiple", key="return_value")
7580
81+
.. versionchanged:: 3.0
82+
83+
In Airflow 3.0+, you can also use the Task Context directly for XCom operations:
84+
85+
.. code-block:: python
86+
87+
from airflow.sdk import get_current_context
7688
7789
90+
@task
91+
def example_task():
92+
context = get_current_context()
93+
ti = context["ti"]
94+
95+
# Push XCom
96+
ti.xcom_push(key="my_key", value="my_value")
97+
98+
# Pull XCom
99+
value = ti.xcom_pull(task_ids="previous_task", key="my_key")
100+
return value
101+
78102
.. note::
79103

80104
If the first task run is not succeeded then on every retry task XComs will be cleared to make the task run idempotent.
@@ -91,7 +115,12 @@ Custom XCom Backends
91115

92116
The XCom system has interchangeable backends, and you can set which backend is being used via the ``xcom_backend`` configuration option.
93117

94-
If you want to implement your own backend, you should subclass :class:`~airflow.models.xcom.BaseXCom`, and override the ``serialize_value`` and ``deserialize_value`` methods.
118+
If you want to implement your own backend, you should subclass :class:`~airflow.sdk.execution_time.xcom.XCom`, and override the ``serialize_value`` and ``deserialize_value`` methods.
119+
120+
.. versionchanged:: 3.0
121+
122+
The base class for custom XCom backends is now :class:`~airflow.sdk.execution_time.xcom.XCom`
123+
from the airflow.sdk namespace.
95124

96125
You can override the ``purge`` method in the ``BaseXCom`` class to have control over purging the xcom data from the custom backend. This will be called as part of ``delete``.
97126

@@ -104,6 +133,6 @@ If you can exec into a terminal in an Airflow container, you can then print out
104133

105134
.. code-block:: python
106135
107-
from airflow.models.xcom import XCom
136+
from airflow.sdk.execution_time.xcom import XCom
108137
109138
print(XCom.__name__)

0 commit comments

Comments
 (0)