diff --git a/airflow/utils/context.py b/airflow/utils/context.py index 62308605dbb37..4430291d944bd 100644 --- a/airflow/utils/context.py +++ b/airflow/utils/context.py @@ -34,7 +34,6 @@ import attrs from sqlalchemy import and_, select -from airflow.exceptions import RemovedInAirflow3Warning from airflow.models.asset import ( AssetAliasModel, AssetEvent, @@ -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. diff --git a/contributing-docs/testing/unit_tests.rst b/contributing-docs/testing/unit_tests.rst index 5a4cf4cac6cf2..bdc670f854a1c 100644 --- a/contributing-docs/testing/unit_tests.rst +++ b/contributing-docs/testing/unit_tests.rst @@ -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. diff --git a/providers/openlineage/src/airflow/providers/openlineage/utils/utils.py b/providers/openlineage/src/airflow/providers/openlineage/utils/utils.py index 9f850d3f9ab34..80c6cbc1fc9e2 100644 --- a/providers/openlineage/src/airflow/providers/openlineage/utils/utils.py +++ b/providers/openlineage/src/airflow/providers/openlineage/utils/utils.py @@ -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 diff --git a/providers/standard/tests/provider_tests/standard/operators/test_python.py b/providers/standard/tests/provider_tests/standard/operators/test_python.py index 9f0f3515c696a..34e18224bdb2a 100644 --- a/providers/standard/tests/provider_tests/standard/operators/test_python.py +++ b/providers/standard/tests/provider_tests/standard/operators/test_python.py @@ -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 @@ -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] @@ -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", [ @@ -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", [ @@ -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", [ @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 547402de6476c..fadc418a9856d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = [ diff --git a/scripts/ci/pre_commit/check_deprecations.py b/scripts/ci/pre_commit/check_deprecations.py index ca6db992c9aef..1920143fbc27f 100755 --- a/scripts/ci/pre_commit/check_deprecations.py +++ b/scripts/ci/pre_commit/check_deprecations.py @@ -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( diff --git a/scripts/ci/testing/summarize_captured_warnings.py b/scripts/ci/testing/summarize_captured_warnings.py index 43daa6775c60c..588bd91c0d953 100755 --- a/scripts/ci/testing/summarize_captured_warnings.py +++ b/scripts/ci/testing/summarize_captured_warnings.py @@ -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 = { diff --git a/tests/cli/commands/remote_commands/test_task_command.py b/tests/cli/commands/remote_commands/test_task_command.py index 6c1414d5fbf80..87d3c1b673d40 100644 --- a/tests/cli/commands/remote_commands/test_task_command.py +++ b/tests/cli/commands/remote_commands/test_task_command.py @@ -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( @@ -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""" @@ -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" @@ -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.