Skip to content

Commit

Permalink
Remove AirflowContextDeprecationWarning as all context should be clea…
Browse files Browse the repository at this point in the history
…n for Airflow 3 (apache#46601)

* Remove AirflowContextDeprecationWarning as all context should be clean for Airflow 3

* Fix issues in CI
  • Loading branch information
jscheffl authored Feb 10, 2025
1 parent 121381d commit 8592188
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 22 deletions.
5 changes: 0 additions & 5 deletions airflow/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import attrs
from sqlalchemy import and_, select

from airflow.exceptions import RemovedInAirflow3Warning
from airflow.models.asset import (
AssetAliasModel,
AssetEvent,
Expand Down Expand Up @@ -269,10 +268,6 @@ def __getitem__(self, key: int | Asset | AssetAlias | AssetRef) -> LazyAssetEven
)


class AirflowContextDeprecationWarning(RemovedInAirflow3Warning):
"""Warn for usage of deprecated context variables in a task."""


def context_merge(context: Context, *args: Any, **kwargs: Any) -> None:
"""
Merge parameters into an existing context.
Expand Down
1 change: 0 additions & 1 deletion contributing-docs/testing/unit_tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ By default, in the new tests selected warnings are prohibited:

* ``airflow.exceptions.AirflowProviderDeprecationWarning``
* ``airflow.exceptions.RemovedInAirflow3Warning``
* ``airflow.utils.context.AirflowContextDeprecationWarning``

That mean if one of this warning appear during test run and do not captured the test will failed.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,9 @@ def _redact(self, item: Redactable, name: str | None, depth: int, max_depth: int
class AirflowContextDeprecationWarning(UserWarning):
pass
else:
from airflow.utils.context import AirflowContextDeprecationWarning
from airflow.utils.context import ( # type: ignore[attr-defined,no-redef]
AirflowContextDeprecationWarning,
)

if depth > max_depth:
return item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
)
from airflow.providers.standard.utils.python_virtualenv import prepare_virtualenv
from airflow.utils import timezone
from airflow.utils.context import AirflowContextDeprecationWarning, Context
from airflow.utils.session import create_session
from airflow.utils.state import DagRunState, State, TaskInstanceState
from airflow.utils.trigger_rule import TriggerRule
Expand All @@ -75,6 +74,7 @@

if TYPE_CHECKING:
from airflow.models.dagrun import DagRun
from airflow.utils.context import Context

pytestmark = [pytest.mark.db_test, pytest.mark.need_serialized_dag]

Expand Down Expand Up @@ -1253,7 +1253,6 @@ def f(a):
# This tests might take longer than default 60 seconds as it is serializing a lot of
# context using dill/cloudpickle (which is slow apparently).
@pytest.mark.execution_timeout(120)
@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
@pytest.mark.parametrize(
"serializer",
[
Expand Down Expand Up @@ -1313,7 +1312,6 @@ def f(

self.run_as_operator(f, serializer=serializer, system_site_packages=True, requirements=None)

@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
@pytest.mark.parametrize(
"serializer",
[
Expand Down Expand Up @@ -1344,7 +1342,6 @@ def f(

self.run_as_task(f, serializer=serializer, system_site_packages=False, requirements=["pendulum"])

@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
@pytest.mark.parametrize(
"serializer",
[
Expand Down Expand Up @@ -1769,10 +1766,12 @@ def execute(self, context: Context):
def get_all_the_context(**context):
current_context = get_current_context()
with warnings.catch_warnings():
warnings.simplefilter("ignore", AirflowContextDeprecationWarning)
if AIRFLOW_V_3_0_PLUS:
assert context == current_context
else:
from airflow.utils.context import AirflowContextDeprecationWarning

warnings.simplefilter("ignore", AirflowContextDeprecationWarning)
assert current_context._context


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ filterwarnings = [
# Instead of that, we use a separate parameter and dynamically add it into `filterwarnings` marker.
forbidden_warnings = [
"airflow.exceptions.RemovedInAirflow3Warning",
"airflow.utils.context.AirflowContextDeprecationWarning",
"airflow.exceptions.AirflowProviderDeprecationWarning",
]
python_files = [
Expand Down
5 changes: 1 addition & 4 deletions scripts/ci/pre_commit/check_deprecations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@


allowed_warnings: dict[str, tuple[str, ...]] = {
"airflow": (
"airflow.exceptions.RemovedInAirflow3Warning",
"airflow.utils.context.AirflowContextDeprecationWarning",
),
"airflow": ("airflow.exceptions.RemovedInAirflow3Warning",),
"providers": ("airflow.exceptions.AirflowProviderDeprecationWarning",),
}
compatible_decorators: frozenset[tuple[str, ...]] = frozenset(
Expand Down
1 change: 0 additions & 1 deletion scripts/ci/testing/summarize_captured_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"pytest.PytestWarning": "!!",
"airflow.exceptions.RemovedInAirflow3Warning": "!",
"airflow.exceptions.AirflowProviderDeprecationWarning": "!",
"airflow.utils.context.AirflowContextDeprecationWarning": "!",
}
# Always print messages for these warning categories
ALWAYS_SHOW_WARNINGS = {
Expand Down
4 changes: 0 additions & 4 deletions tests/cli/commands/remote_commands/test_task_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def test_cli_list_tasks(self):
args = self.parser.parse_args(["tasks", "list", dag_id])
task_command.task_list(args)

@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
def test_test(self):
"""Test the `airflow test` command"""
args = self.parser.parse_args(
Expand All @@ -134,7 +133,6 @@ def test_test(self):
# Check that prints, and log messages, are shown
assert "'example_python_operator__print_the_context__20180101'" in stdout.getvalue()

@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
@mock.patch("airflow.utils.timezone.utcnow")
def test_test_no_logical_date(self, mock_utcnow):
"""Test the `airflow test` command"""
Expand Down Expand Up @@ -245,7 +243,6 @@ def test_task_render_with_custom_timetable(self, mock_fetch_dag_run_from_run_id_

mock_fetch_dag_run_from_run_id_or_logical_date_string.assert_called_once()

@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
def test_test_with_existing_dag_run(self, caplog):
"""Test the `airflow test` command"""
task_id = "print_the_context"
Expand All @@ -258,7 +255,6 @@ def test_test_with_existing_dag_run(self, caplog):
)

@pytest.mark.enable_redact
@pytest.mark.filterwarnings("ignore::airflow.utils.context.AirflowContextDeprecationWarning")
def test_test_filters_secrets(self, capsys):
"""Test ``airflow test`` does not print secrets to stdout.
Expand Down

0 comments on commit 8592188

Please sign in to comment.