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 2022/08/05 17:28:42 UTC
[airflow] branch main updated: Fix S3Hook transfer config arguments validation (#25544)
This is an automated email from the ASF dual-hosted git repository.
potiuk 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 d4f560b98e Fix S3Hook transfer config arguments validation (#25544)
d4f560b98e is described below
commit d4f560b98e3b397dc710c97bbe4743abe941d8ad
Author: Andrey Anshin <An...@taragol.is>
AuthorDate: Fri Aug 5 21:28:36 2022 +0400
Fix S3Hook transfer config arguments validation (#25544)
* Fix S3Hook transfer config arguments validation
* Add proper exception type
---
airflow/providers/amazon/aws/hooks/s3.py | 6 +++---
tests/providers/amazon/aws/hooks/test_s3.py | 9 ++++++---
2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/airflow/providers/amazon/aws/hooks/s3.py b/airflow/providers/amazon/aws/hooks/s3.py
index 9c46b78685..8bd3f0e670 100644
--- a/airflow/providers/amazon/aws/hooks/s3.py
+++ b/airflow/providers/amazon/aws/hooks/s3.py
@@ -128,12 +128,12 @@ class S3Hook(AwsBaseHook):
kwargs['client_type'] = 's3'
kwargs['aws_conn_id'] = aws_conn_id
- if extra_args and not isinstance(extra_args, dict):
- raise ValueError(f"transfer_config_args '{extra_args!r}' must be of type {dict}")
+ if transfer_config_args and not isinstance(transfer_config_args, dict):
+ raise TypeError(f"transfer_config_args expected dict, got {type(transfer_config_args).__name__}.")
self.transfer_config = TransferConfig(**transfer_config_args or {})
if extra_args and not isinstance(extra_args, dict):
- raise ValueError(f"extra_args '{extra_args!r}' must be of type {dict}")
+ raise TypeError(f"extra_args expected dict, got {type(extra_args).__name__}.")
self._extra_args = extra_args or {}
super().__init__(*args, **kwargs)
diff --git a/tests/providers/amazon/aws/hooks/test_s3.py b/tests/providers/amazon/aws/hooks/test_s3.py
index 35f77a6d17..f368bfdd82 100644
--- a/tests/providers/amazon/aws/hooks/test_s3.py
+++ b/tests/providers/amazon/aws/hooks/test_s3.py
@@ -55,16 +55,19 @@ class TestAwsS3Hook:
hook = S3Hook()
assert hook.get_conn() is not None
- @mock_s3
def test_use_threads_default_value(self):
hook = S3Hook()
assert hook.transfer_config.use_threads is True
- @mock_s3
def test_use_threads_set_value(self):
hook = S3Hook(transfer_config_args={"use_threads": False})
assert hook.transfer_config.use_threads is False
+ @pytest.mark.parametrize("transfer_config_args", [1, True, '{"use_threads": false}'])
+ def test_transfer_config_args_invalid(self, transfer_config_args):
+ with pytest.raises(TypeError, match="transfer_config_args expected dict, got .*"):
+ S3Hook(transfer_config_args=transfer_config_args)
+
def test_parse_s3_url(self):
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"
@@ -509,7 +512,7 @@ class TestAwsS3Hook:
assert {"AWSAccessKeyId", "Signature", "Expires"}.issubset(set(params.keys()))
def test_should_throw_error_if_extra_args_is_not_dict(self):
- with pytest.raises(ValueError):
+ with pytest.raises(TypeError, match="extra_args expected dict, got .*"):
S3Hook(extra_args=1)
def test_should_throw_error_if_extra_args_contains_unknown_arg(self, s3_bucket):