From 47bf6075ad47dc3cd3c0873816fd3b521af69d23 Mon Sep 17 00:00:00 2001 From: Abdel Jaidi Date: Tue, 17 Sep 2024 10:58:57 +0100 Subject: [PATCH 1/4] fix: handle case of str to bool env variable in config --- awswrangler/_config.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/awswrangler/_config.py b/awswrangler/_config.py index af065beca..82701b505 100644 --- a/awswrangler/_config.py +++ b/awswrangler/_config.py @@ -224,6 +224,8 @@ def _apply_type(name: str, value: Any, dtype: type[_ConfigValueType], nullable: raise exceptions.InvalidArgumentValue( f"{name} configuration does not accept a null value. Please pass {dtype}." ) + if isinstance(value, str) and dtype is bool: + return _Config._cast_bool(name=name, value=value.lower()) try: return dtype(value) if isinstance(value, dtype) is False else value except ValueError as ex: @@ -239,6 +241,14 @@ def _is_null(value: _ConfigValueType | None) -> bool: return True return False + @staticmethod + def _cast_bool(name: str, value: str) -> bool: + _true = ("true", "1") + _false = ("false", "0") + if value not in _true + _false: + raise exceptions.InvalidArgumentValue(f"{name} configuration only accepts True/False or 0/1.") + return value in _true + @property def catalog_id(self) -> str | None: """Property catalog_id.""" From 2c757db383748d1ad4aaedec5b172066b2ff8cd4 Mon Sep 17 00:00:00 2001 From: Abdel Jaidi Date: Tue, 17 Sep 2024 13:14:56 +0100 Subject: [PATCH 2/4] fix: add missing empty case --- awswrangler/_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awswrangler/_config.py b/awswrangler/_config.py index 82701b505..5d587400a 100644 --- a/awswrangler/_config.py +++ b/awswrangler/_config.py @@ -244,7 +244,7 @@ def _is_null(value: _ConfigValueType | None) -> bool: @staticmethod def _cast_bool(name: str, value: str) -> bool: _true = ("true", "1") - _false = ("false", "0") + _false = ("false", "0", "") if value not in _true + _false: raise exceptions.InvalidArgumentValue(f"{name} configuration only accepts True/False or 0/1.") return value in _true From 4af7e52938d066911c9ac12841435e47d5020e83 Mon Sep 17 00:00:00 2001 From: Abdel Jaidi Date: Wed, 2 Oct 2024 15:01:42 +0100 Subject: [PATCH 3/4] fix: PR feedback --- awswrangler/_config.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/awswrangler/_config.py b/awswrangler/_config.py index 5d587400a..57c1fd6f7 100644 --- a/awswrangler/_config.py +++ b/awswrangler/_config.py @@ -224,8 +224,9 @@ def _apply_type(name: str, value: Any, dtype: type[_ConfigValueType], nullable: raise exceptions.InvalidArgumentValue( f"{name} configuration does not accept a null value. Please pass {dtype}." ) + # Handle case where string is empty, "False" or "0" if isinstance(value, str) and dtype is bool: - return _Config._cast_bool(name=name, value=value.lower()) + return value.lower() in ("false", "0", "") try: return dtype(value) if isinstance(value, dtype) is False else value except ValueError as ex: @@ -241,14 +242,6 @@ def _is_null(value: _ConfigValueType | None) -> bool: return True return False - @staticmethod - def _cast_bool(name: str, value: str) -> bool: - _true = ("true", "1") - _false = ("false", "0", "") - if value not in _true + _false: - raise exceptions.InvalidArgumentValue(f"{name} configuration only accepts True/False or 0/1.") - return value in _true - @property def catalog_id(self) -> str | None: """Property catalog_id.""" From cc32ceb0cdfdd86e897aed17f283c87c6f24bfbd Mon Sep 17 00:00:00 2001 From: Abdel Jaidi Date: Wed, 2 Oct 2024 15:15:45 +0100 Subject: [PATCH 4/4] not in --- awswrangler/_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/awswrangler/_config.py b/awswrangler/_config.py index 57c1fd6f7..a1c7e9da5 100644 --- a/awswrangler/_config.py +++ b/awswrangler/_config.py @@ -224,9 +224,9 @@ def _apply_type(name: str, value: Any, dtype: type[_ConfigValueType], nullable: raise exceptions.InvalidArgumentValue( f"{name} configuration does not accept a null value. Please pass {dtype}." ) - # Handle case where string is empty, "False" or "0" + # Handle case where string is empty, "False" or "0". Anything else is True if isinstance(value, str) and dtype is bool: - return value.lower() in ("false", "0", "") + return value.lower() not in ("false", "0", "") try: return dtype(value) if isinstance(value, dtype) is False else value except ValueError as ex: