Skip to content

Commit 3e9e082

Browse files
committed
Remove conf from Task Context
This was initially added in response to #168. However, we now have `ti.log_url` that is used for that; example usages: https://github.com/apache/airflow/blob/dcd41f60f1c9b5583b49bfb49b6d85c640a2892c/airflow/models/taskinstance.py#L1362 https://github.com/apache/airflow/blob/dcd41f60f1c9b5583b49bfb49b6d85c640a2892c/providers/src/airflow/providers/smtp/notifications/templates/email.html#L28 https://github.com/apache/airflow/blob/dcd41f60f1c9b5583b49bfb49b6d85c640a2892c/docs/apache-airflow/howto/email-config.rst?plain=1#L76 So, to simplify what we need to pass from API server to the Task SDK, I want to simplify and remove things that aren't needed. In this case, this is good so we don't pass/expore secrets unnecesarily via `conf`
1 parent 16022e0 commit 3e9e082

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

airflow/models/taskinstance.py

-1
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,6 @@ def get_triggering_events() -> dict[str, list[AssetEvent]]:
10101010
# * KNOWN_CONTEXT_KEYS in airflow/utils/context.py
10111011
# * Table in docs/apache-airflow/templates-ref.rst
10121012
context: dict[str, Any] = {
1013-
"conf": conf,
10141013
"dag": dag,
10151014
"dag_run": dag_run,
10161015
"data_interval_end": timezone.coerce_datetime(data_interval.end),

airflow/utils/context.py

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
# * Context in airflow/utils/context.pyi.
6868
# * Table in docs/apache-airflow/templates-ref.rst
6969
KNOWN_CONTEXT_KEYS: set[str] = {
70-
"conf",
7170
"conn",
7271
"dag",
7372
"dag_run",

airflow/utils/context.pyi

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ from typing import Any, overload
3232
from pendulum import DateTime
3333
from sqlalchemy.orm import Session
3434

35-
from airflow.configuration import AirflowConfigParser
3635
from airflow.models.asset import AssetEvent
3736
from airflow.models.baseoperator import BaseOperator
3837
from airflow.models.dag import DAG
@@ -100,7 +99,6 @@ class InletEventsAccessors(Mapping[Asset | AssetAlias, InletEventsAccessor]):
10099
# * KNOWN_CONTEXT_KEYS in airflow/utils/context.py
101100
# * Table in docs/apache-airflow/templates-ref.rst
102101
class Context(TypedDict, total=False):
103-
conf: AirflowConfigParser
104102
conn: Any
105103
dag: DAG
106104
dag_run: DagRun | DagRunPydantic

docs/apache-airflow/templates-ref.rst

-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ Variable Type Description
7979
``{{ conn }}`` Airflow connections. See `Airflow Connections in Templates`_ below.
8080
``{{ task_instance_key_str }}`` str | A unique, human-readable key to the task instance. The format is
8181
| ``{dag_id}__{task_id}__{ds_nodash}``.
82-
``{{ conf }}`` AirflowConfigParser | The full configuration object representing the content of your
83-
| ``airflow.cfg``. See :mod:`airflow.configuration.conf`.
8482
``{{ run_id }}`` str The currently running :class:`~airflow.models.dagrun.DagRun` run ID.
8583
``{{ dag_run }}`` DagRun The currently running :class:`~airflow.models.dagrun.DagRun`.
8684
``{{ test_mode }}`` bool Whether the task instance was run by the ``airflow test`` CLI.

newsfragments/44820.significant.rst

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Removed ``conf`` from the Task template context
2+
3+
The ``conf`` variable, which provided access to the full Airflow configuration (``airflow.cfg``), has been
4+
removed from the Task (Jinja2) template context for security and simplicity. If you
5+
need specific configuration values in your tasks, retrieve them explicitly in your DAG or task code
6+
using the ``airflow.configuration.conf`` module.
7+
8+
For users retrieving the webserver URL (e.g., to include log links in task or callbacks), one of the
9+
most common use-case, use the ``ti.log_url`` property available in the ``TaskInstance`` context instead.
10+
11+
Example:
12+
13+
.. code-block:: python
14+
15+
PythonOperator(
16+
task_id="my_task",
17+
python_callable=my_task_callable,
18+
on_failure_callback=SmtpNotifier(
19+
from_email="[email protected]",
20+
21+
subject="Task {{ ti.task_id }} failed",
22+
html_content="Task <b>{{ ti.task_id }}</b> failed. Log URL: {{ ti.log_url }}",
23+
),
24+
)
25+
26+
* Types of change
27+
28+
* [x] DAG changes
29+
* [ ] Config changes
30+
* [ ] API changes
31+
* [ ] CLI changes
32+
* [ ] Behaviour changes
33+
* [ ] Plugin changes
34+
* [ ] Dependency changes
35+
36+
* Migration rules needed
37+
38+
* Remove context key ``conf``

0 commit comments

Comments
 (0)