This is an automated email from the ASF dual-hosted git repository.

shahar1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new f781f8b8785 Keep S3DeleteObjectsOperator validation in __init__, 
narrow to ValueError (#70359)
f781f8b8785 is described below

commit f781f8b8785496d68c9d9ae725a004764bbc9f1d
Author: Amogh Atreya <[email protected]>
AuthorDate: Thu Jul 30 12:26:20 2026 +0530

    Keep S3DeleteObjectsOperator validation in __init__, narrow to ValueError 
(#70359)
---
 generated/known_airflow_exceptions.txt                            | 2 +-
 providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py | 8 ++++++--
 providers/amazon/tests/unit/amazon/aws/operators/test_s3.py       | 2 +-
 scripts/ci/prek/validate_operators_init_exemptions.txt            | 1 -
 4 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/generated/known_airflow_exceptions.txt 
b/generated/known_airflow_exceptions.txt
index 1fb46185490..66ee6590bc8 100644
--- a/generated/known_airflow_exceptions.txt
+++ b/generated/known_airflow_exceptions.txt
@@ -85,7 +85,7 @@ 
providers/amazon/src/airflow/providers/amazon/aws/operators/neptune.py::4
 providers/amazon/src/airflow/providers/amazon/aws/operators/rds.py::4
 
providers/amazon/src/airflow/providers/amazon/aws/operators/redshift_cluster.py::9
 providers/amazon/src/airflow/providers/amazon/aws/operators/redshift_data.py::2
-providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py::5
+providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py::4
 providers/amazon/src/airflow/providers/amazon/aws/operators/sagemaker.py::22
 
providers/amazon/src/airflow/providers/amazon/aws/operators/sagemaker_unified_studio.py::2
 providers/amazon/src/airflow/providers/amazon/aws/operators/step_function.py::2
diff --git a/providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py 
b/providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py
index b74fb60a1b7..164777c78c1 100644
--- a/providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py
+++ b/providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py
@@ -697,8 +697,12 @@ class S3DeleteObjectsOperator(AwsBaseOperator[S3Hook]):
 
         self._keys: str | list[str] = ""
 
-        if not exactly_one(keys is None, all(var is None for var in [prefix, 
from_datetime, to_datetime])):
-            raise AirflowException(
+        # Checked here and again in execute(): this guard keeps a plain 
authoring mistake a
+        # parse-time error, while execute() catches a templated `keys` that 
renders to None
+        # (which would otherwise list — and delete from — the whole bucket).
+        by_scan = prefix is not None or from_datetime is not None or 
to_datetime is not None
+        if not exactly_one(keys is not None, by_scan):
+            raise ValueError(
                 "Either keys or at least one of prefix, from_datetime, 
to_datetime should be set."
             )
 
diff --git a/providers/amazon/tests/unit/amazon/aws/operators/test_s3.py 
b/providers/amazon/tests/unit/amazon/aws/operators/test_s3.py
index cd907171927..9d062caa4ac 100644
--- a/providers/amazon/tests/unit/amazon/aws/operators/test_s3.py
+++ b/providers/amazon/tests/unit/amazon/aws/operators/test_s3.py
@@ -1120,7 +1120,7 @@ class TestS3DeleteObjectsOperator:
     )
     def test_validate_keys_and_filters_in_constructor(self, keys, prefix, 
from_datetime, to_datetime):
         with pytest.raises(
-            AirflowException,
+            ValueError,
             match=r"Either keys or at least one of prefix, from_datetime, 
to_datetime should be set.",
         ):
             S3DeleteObjectsOperator(
diff --git a/scripts/ci/prek/validate_operators_init_exemptions.txt 
b/scripts/ci/prek/validate_operators_init_exemptions.txt
index 559ff95bdff..c993ca2a163 100644
--- a/scripts/ci/prek/validate_operators_init_exemptions.txt
+++ b/scripts/ci/prek/validate_operators_init_exemptions.txt
@@ -7,7 +7,6 @@
 # Burn-down tracked at https://github.com/apache/airflow/issues/70296
 
providers/amazon/src/airflow/providers/amazon/aws/operators/neptune.py::NeptuneStartDbClusterOperator
 
providers/amazon/src/airflow/providers/amazon/aws/operators/neptune.py::NeptuneStopDbClusterOperator
-providers/amazon/src/airflow/providers/amazon/aws/operators/s3.py::S3DeleteObjectsOperator
 
providers/amazon/src/airflow/providers/amazon/aws/operators/sagemaker.py::SageMakerCreateNotebookOperator
 
providers/amazon/src/airflow/providers/amazon/aws/operators/sagemaker.py::SageMakerProcessingOperator
 
providers/amazon/src/airflow/providers/amazon/aws/transfers/gcs_to_s3.py::GCSToS3Operator

Reply via email to