Skip to content

Commit 6a2ff20

Browse files
committed
docs: replace direct metadata model imports in how-to examples with airflow.sdk
1 parent c905ad0 commit 6a2ff20

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ To use them, just import and call ``get`` on the Variable model::
3333
# Returns the value of default (None) if the variable is not set
3434
baz = Variable.get("baz", default=None)
3535

36+
.. versionchanged:: 3.0
37+
38+
In Airflow 3.0+, you can also access variables through the Task Context using
39+
:func:`~airflow.sdk.get_current_context`:
40+
41+
.. code-block:: python
42+
43+
from airflow.sdk import get_current_context
44+
45+
46+
def my_task():
47+
context = get_current_context()
48+
var = context["var"]
49+
my_variable = var.get("my_variable_name")
50+
return my_variable
51+
3652
You can also use them from :ref:`templates <concepts:jinja-templating>`::
3753

3854
# Raw value

airflow-core/docs/howto/connection.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ Managing Connections
2222

2323
For an overview of hooks and connections, see :doc:`/authoring-and-scheduling/connections`.
2424

25-
Airflow's :class:`~airflow.models.connection.Connection` object is used for storing credentials and other information necessary for connecting to external services.
25+
.. versionchanged:: 3.0
26+
27+
Direct metadata-model access to :class:`~airflow.models.connection.Connection` in task or management code is deprecated.
28+
Use the public SDK API (:class:`~airflow.sdk.Connection`), the Stable REST API, or the Python Client instead.
29+
30+
Airflow's :class:`~airflow.sdk.Connection` object is used for storing credentials and other information necessary for connecting to external services.
2631

2732
Connections may be defined in the following ways:
2833

@@ -77,7 +82,7 @@ convenience property :py:meth:`~airflow.models.connection.Connection.as_json`. I
7782

7883
.. code-block:: pycon
7984
80-
>>> from airflow.models.connection import Connection
85+
>>> from airflow.sdk import Connection
8186
>>> c = Connection(
8287
... conn_id="some_conn",
8388
... conn_type="mysql",
@@ -94,7 +99,7 @@ In addition, same approach could be used to convert Connection from URI format t
9499

95100
.. code-block:: pycon
96101
97-
>>> from airflow.models.connection import Connection
102+
>>> from airflow.sdk import Connection
98103
>>> c = Connection(
99104
... conn_id="awesome_conn",
100105
... description="Example Connection",

airflow-core/docs/howto/custom-operator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Creating a custom Operator
2424
Airflow allows you to create new operators to suit the requirements of you or your team.
2525
This extensibility is one of the many features which make Apache Airflow powerful.
2626

27-
You can create any operator you want by extending the :class:`airflow.models.baseoperator.BaseOperator`
27+
You can create any operator you want by extending the public SDK base class :class:`~airflow.sdk.BaseOperator`.
2828

2929
There are two methods that you need to override in a derived class:
3030

0 commit comments

Comments
 (0)