You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2021/05/27 09:29:23 UTC

[airflow] branch master updated: Remove the `not-allow-trailing-slash` rule on S3_hook (#15609)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 5fbc86f  Remove the `not-allow-trailing-slash` rule on S3_hook (#15609)
5fbc86f is described below

commit 5fbc86f0364fbc4f7c2ba10cae4a13449709730c
Author: Isaacwhyuenac <13...@users.noreply.github.com>
AuthorDate: Thu May 27 18:28:47 2021 +0900

    Remove the `not-allow-trailing-slash` rule on S3_hook (#15609)
---
 airflow/providers/amazon/aws/hooks/s3.py    | 2 +-
 tests/providers/amazon/aws/hooks/test_s3.py | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/airflow/providers/amazon/aws/hooks/s3.py b/airflow/providers/amazon/aws/hooks/s3.py
index 2e18754..990ee82 100644
--- a/airflow/providers/amazon/aws/hooks/s3.py
+++ b/airflow/providers/amazon/aws/hooks/s3.py
@@ -143,7 +143,7 @@ class S3Hook(AwsBaseHook):
             raise AirflowException(f'Please provide a bucket_name instead of "{s3url}"')
 
         bucket_name = parsed_url.netloc
-        key = parsed_url.path.strip('/')
+        key = parsed_url.path.lstrip('/')
 
         return bucket_name, key
 
diff --git a/tests/providers/amazon/aws/hooks/test_s3.py b/tests/providers/amazon/aws/hooks/test_s3.py
index b56d4fc..0f7da9b 100644
--- a/tests/providers/amazon/aws/hooks/test_s3.py
+++ b/tests/providers/amazon/aws/hooks/test_s3.py
@@ -69,6 +69,10 @@ class TestAwsS3Hook:
         parsed = S3Hook.parse_s3_url("s3://test/this/is/not/a-real-key.txt")
         assert parsed == ("test", "this/is/not/a-real-key.txt"), "Incorrect parsing of the s3 url"
 
+    def test_parse_s3_object_directory(self):
+        parsed = S3Hook.parse_s3_url("s3://test/this/is/not/a-real-s3-directory/")
+        assert parsed == ("test", "this/is/not/a-real-s3-directory/"), "Incorrect parsing of the s3 url"
+
     def test_check_for_bucket(self, s3_bucket):
         hook = S3Hook()
         assert hook.check_for_bucket(s3_bucket) is True