From 054782ee16bd638c63bb37701d841a98d51a8b0f Mon Sep 17 00:00:00 2001 From: Jake Yip Date: Wed, 1 May 2019 11:37:31 +1000 Subject: [PATCH] allow an empty string to unset options For command `alarm update`, options like `--alarm-actions` cannot be unset. Update utils to allow user to pass in an empty string in command line to unset these values. Change-Id: Ib6c712d8ad1a69b16dfef83362c576e80223f5a2 --- aodhclient/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aodhclient/utils.py b/aodhclient/utils.py index 11609ec..8d2fd55 100644 --- a/aodhclient/utils.py +++ b/aodhclient/utils.py @@ -131,7 +131,14 @@ def dict_from_parsed_args(parsed_args, attrs): else: value = getattr(parsed_args, attr) if value is not None: - d[attr] = value + if value == [""]: + # NOTE(jake): As options like --alarm-actions is an array, + # their value can be array with empty string if user set option + # to ''. In this case we set it to None here so that a None + # value gets sent to API. + d[attr] = None + else: + d[attr] = value return d