From 6ad8a506b264b735f9fbfedb74741c5109bc3c6d Mon Sep 17 00:00:00 2001 From: Kaxil Naik Date: Tue, 24 Jun 2025 23:15:40 +0530 Subject: [PATCH 1/2] Add deprecation to `airflow/sensors/base.py` Had to todo earlier, resolved that. --- airflow-core/src/airflow/sensors/__init__.py | 6 ++++- airflow-core/src/airflow/sensors/base.py | 24 -------------------- 2 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 airflow-core/src/airflow/sensors/base.py diff --git a/airflow-core/src/airflow/sensors/__init__.py b/airflow-core/src/airflow/sensors/__init__.py index 62a4037df2f66..db378f4550324 100644 --- a/airflow-core/src/airflow/sensors/__init__.py +++ b/airflow-core/src/airflow/sensors/__init__.py @@ -26,8 +26,12 @@ from airflow.utils.deprecation_tools import add_deprecated_classes -# TODO: Add definition from Task SDK here and remove `base.py` file __deprecated_classes = { + "base": { + "BaseSensorOperator": "airflow.sdk.bases.sensor.BaseSensorOperator", + "PokeReturnValue": "airflow.sdk.bases.sensor.PokeReturnValue", + "poke_mode_only": "airflow.sdk.bases.sensor.poke_mode_only", + }, "python":{ "PythonSensor": "airflow.providers.standard.sensors.python.PythonSensor", }, diff --git a/airflow-core/src/airflow/sensors/base.py b/airflow-core/src/airflow/sensors/base.py deleted file mode 100644 index 71ae006f53437..0000000000000 --- a/airflow-core/src/airflow/sensors/base.py +++ /dev/null @@ -1,24 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -from __future__ import annotations - -from airflow.sdk.bases.sensor import ( - BaseSensorOperator as BaseSensorOperator, - PokeReturnValue as PokeReturnValue, - poke_mode_only as poke_mode_only, -) From e41bd6ea0408bd921e70e7b4f77f52f63bc9868f Mon Sep 17 00:00:00 2001 From: Pavan Kumar Date: Tue, 24 Jun 2025 22:50:05 +0100 Subject: [PATCH 2/2] Add sensor Deprecation --- .../src/airflow/providers/standard/sensors/date_time.py | 4 ++-- .../src/airflow/providers/standard/sensors/external_task.py | 2 +- .../src/airflow/providers/standard/sensors/time_delta.py | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/providers/standard/src/airflow/providers/standard/sensors/date_time.py b/providers/standard/src/airflow/providers/standard/sensors/date_time.py index b1c5b5da2976d..419e3c49ea601 100644 --- a/providers/standard/src/airflow/providers/standard/sensors/date_time.py +++ b/providers/standard/src/airflow/providers/standard/sensors/date_time.py @@ -20,7 +20,7 @@ import datetime from collections.abc import Sequence from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, NoReturn +from typing import TYPE_CHECKING, Any from airflow.providers.standard.triggers.temporal import DateTimeTrigger from airflow.providers.standard.version_compat import AIRFLOW_V_3_0_PLUS @@ -147,7 +147,7 @@ def __init__( end_from_trigger=self.end_from_trigger, ) - def execute(self, context: Context) -> NoReturn: + def execute(self, context: Context) -> None: self.defer( method_name="execute_complete", trigger=DateTimeTrigger( diff --git a/providers/standard/src/airflow/providers/standard/sensors/external_task.py b/providers/standard/src/airflow/providers/standard/sensors/external_task.py index cc27679773d4b..aa8a971a526b8 100644 --- a/providers/standard/src/airflow/providers/standard/sensors/external_task.py +++ b/providers/standard/src/airflow/providers/standard/sensors/external_task.py @@ -46,7 +46,7 @@ if AIRFLOW_V_3_0_PLUS: from airflow.sdk.bases.sensor import BaseSensorOperator else: - from airflow.sensors.base import BaseSensorOperator + from airflow.sensors.base import BaseSensorOperator # type:ignore[no-redef] from airflow.utils.session import NEW_SESSION, provide_session if TYPE_CHECKING: diff --git a/providers/standard/src/airflow/providers/standard/sensors/time_delta.py b/providers/standard/src/airflow/providers/standard/sensors/time_delta.py index 40ad809343bb7..7f1a6cf97ad3d 100644 --- a/providers/standard/src/airflow/providers/standard/sensors/time_delta.py +++ b/providers/standard/src/airflow/providers/standard/sensors/time_delta.py @@ -20,7 +20,7 @@ import warnings from datetime import datetime, timedelta from time import sleep -from typing import TYPE_CHECKING, Any, NoReturn +from typing import TYPE_CHECKING, Any from deprecated.classic import deprecated from packaging.version import Version @@ -106,7 +106,7 @@ def poke(self, context: Context) -> bool: Asynchronous execution """ - def execute(self, context: Context) -> bool | NoReturn: + def execute(self, context: Context) -> bool | None: """ Depending on the deferrable flag, either execute the sensor in a blocking way or defer it. @@ -147,6 +147,8 @@ def execute(self, context: Context) -> bool | NoReturn: timeout=timeout, ) + return None + def execute_complete(self, context: Context, event: Any = None) -> None: """Handle the event when the trigger fires and return immediately.""" return None