airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] ashb closed pull request #3762: [AIRFLOW-2913] Check bucket_key/bucket_name combination in S3KeySensor()
Date Fri, 17 Aug 2018 18:47:12 GMT
ashb closed pull request #3762: [AIRFLOW-2913] Check bucket_key/bucket_name combination in

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/sensors/ b/airflow/sensors/
index fa2eb786ff..246b4c3e73 100644
--- a/airflow/sensors/
+++ b/airflow/sensors/
@@ -32,9 +32,11 @@ class S3KeySensor(BaseSensorOperator):
     a resource.
     :param bucket_key: The key being waited on. Supports full s3:// style url
-        or relative path from root level.
+        or relative path from root level. When it's specified as a full s3://
+        url, please leave bucket_name as `None`.
     :type bucket_key: str
-    :param bucket_name: Name of the S3 bucket
+    :param bucket_name: Name of the S3 bucket. Only needed when ``bucket_key``
+        is not provided as a full s3:// url.
     :type bucket_name: str
     :param wildcard_match: whether the bucket_key should be interpreted as a
         Unix wildcard pattern
@@ -64,6 +66,12 @@ def __init__(self,
                     bucket_key = parsed_url.path[1:]
                     bucket_key = parsed_url.path
+        else:
+            parsed_url = urlparse(bucket_key)
+            if parsed_url.scheme != '' or parsed_url.netloc != '':
+                raise AirflowException('If bucket_name is provided, bucket_key' +
+                                       ' should be relative path from root' +
+                                       ' level, rather than a full s3:// url')
         self.bucket_name = bucket_name
         self.bucket_key = bucket_key
         self.wildcard_match = wildcard_match
diff --git a/tests/sensors/ b/tests/sensors/
new file mode 100644
index 0000000000..a6e77058d8
--- /dev/null
+++ b/tests/sensors/
@@ -0,0 +1,44 @@
+# -*- coding: utf-8 -*-
+# 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
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+import unittest
+from airflow.exceptions import AirflowException
+from airflow.sensors.s3_key_sensor import S3KeySensor
+class S3KeySensorTests(unittest.TestCase):
+    def test_bucket_name_None_and_bucket_key_as_relative_path(self):
+        """
+        Test if exception is raised when bucket_name is None
+        and bucket_key is provided as relative path rather than s3:// url.
+        :return:
+        """
+        with self.assertRaises(AirflowException):
+            S3KeySensor(bucket_key="file_in_bucket")
+    def test_bucket_name_provided_and_bucket_key_is_s3_url(self):
+        """
+        Test if exception is raised when bucket_name is provided
+        while bucket_key is provided as a full s3:// url.
+        :return:
+        """
+        with self.assertRaises(AirflowException):
+            S3KeySensor(bucket_key="s3://test_bucket/file",
+                        bucket_name='test_bucket')


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

View raw message