diff options
author | Sloane Hertel <19572925+s-hertel@users.noreply.github.com> | 2023-04-18 13:02:01 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 12:02:01 -0500 |
commit | 2c35d46298f75098302eb9d49e943ac01cc9a7f5 (patch) | |
tree | a12881c41172e15a583f2b9b9ea37f6fc69300f1 /lib/ansible | |
parent | f90c7f1a7d38f317b3d22977f06ef1b15311a4a7 (diff) | |
download | ansible-2c35d46298f75098302eb9d49e943ac01cc9a7f5.tar.gz |
argspec - fix validating type for required options that are None (#79677) (#80542)
* Only bypass type validation for null parameters if the default is None. A default is mutually exclusive with required.
* Prevent coercing None to str type. Fail the type check instead.
(cherry picked from commit 694c11d5bdc7f5f7779d27315bec939dc9162ec6)
Diffstat (limited to 'lib/ansible')
-rw-r--r-- | lib/ansible/module_utils/common/parameters.py | 2 | ||||
-rw-r--r-- | lib/ansible/module_utils/common/validation.py | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/ansible/module_utils/common/parameters.py b/lib/ansible/module_utils/common/parameters.py index cc94889e4b..386eb875ce 100644 --- a/lib/ansible/module_utils/common/parameters.py +++ b/lib/ansible/module_utils/common/parameters.py @@ -609,7 +609,7 @@ def _validate_argument_types(argument_spec, parameters, prefix='', options_conte continue value = parameters[param] - if value is None: + if value is None and not spec.get('required') and spec.get('default') is None: continue wanted_type = spec.get('type') diff --git a/lib/ansible/module_utils/common/validation.py b/lib/ansible/module_utils/common/validation.py index 5a4cebbc20..fa494d4d61 100644 --- a/lib/ansible/module_utils/common/validation.py +++ b/lib/ansible/module_utils/common/validation.py @@ -381,7 +381,7 @@ def check_type_str(value, allow_conversion=True, param=None, prefix=''): if isinstance(value, string_types): return value - if allow_conversion: + if allow_conversion and value is not None: return to_native(value, errors='surrogate_or_strict') msg = "'{0!r}' is not a string and conversion is not allowed".format(value) |