Skip to content

Commit 47bf607

Browse files
committed
fix: handle case of str to bool env variable in config
1 parent 8cef750 commit 47bf607

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

awswrangler/_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ def _apply_type(name: str, value: Any, dtype: type[_ConfigValueType], nullable:
224224
raise exceptions.InvalidArgumentValue(
225225
f"{name} configuration does not accept a null value. Please pass {dtype}."
226226
)
227+
if isinstance(value, str) and dtype is bool:
228+
return _Config._cast_bool(name=name, value=value.lower())
227229
try:
228230
return dtype(value) if isinstance(value, dtype) is False else value
229231
except ValueError as ex:
@@ -239,6 +241,14 @@ def _is_null(value: _ConfigValueType | None) -> bool:
239241
return True
240242
return False
241243

244+
@staticmethod
245+
def _cast_bool(name: str, value: str) -> bool:
246+
_true = ("true", "1")
247+
_false = ("false", "0")
248+
if value not in _true + _false:
249+
raise exceptions.InvalidArgumentValue(f"{name} configuration only accepts True/False or 0/1.")
250+
return value in _true
251+
242252
@property
243253
def catalog_id(self) -> str | None:
244254
"""Property catalog_id."""

0 commit comments

Comments
 (0)