From 9e59a7df8ef56dece0bec7a21ea8855fa198f5ac Mon Sep 17 00:00:00 2001 From: Steve McGrath Date: Tue, 13 Aug 2024 14:37:58 -0500 Subject: [PATCH] Better handling of null values from SC. Corrected float conversion errors #291 --- .gitignore | 2 ++ tenb2jira/jira/field.py | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 38d5673..156380e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ __pycache__ .coverage *.egg-info /dist +/mapping.db +/base_config_tsc.toml diff --git a/tenb2jira/jira/field.py b/tenb2jira/jira/field.py index e9a0938..be15a5f 100644 --- a/tenb2jira/jira/field.py +++ b/tenb2jira/jira/field.py @@ -129,6 +129,8 @@ def parse_value(self, finding: dict) -> Any: # fetch the value using the defined attribute value = finding.get(self.attribute) + if not value or value == '': + return None # Next we will perform some formatting based on the expected values # that Jira expects in the API. @@ -148,21 +150,17 @@ def parse_value(self, finding: dict) -> Any: case 'labels': if isinstance(value, list): return [str(i) for i in value] - elif value is None: - return [] else: return [v.strip() for v in str(value).split(',')] # float values should always be returned as a float. case 'float': - return float(value) if value is not None else 0.0 + return str(float(value)) # datetime values should be returned in a specific format. Here # we attempt to normalize both timestamp and ISO formatted values # info the Jira-specified format. case 'datetime': - if value is None: - return None try: return arrow.get(value).format(DATETIME_FMT) except arrow.parser.ParserError: @@ -172,8 +170,6 @@ def parse_value(self, finding: dict) -> Any: # we attempt to normalize both timestamp and ISO formatted values # info the Jira-specified format. case 'datepicker': - if value is None: - return None try: return arrow.get(value).format(DATE_FMT) except arrow.parser.ParserError: @@ -199,7 +195,7 @@ def parse_jql(self, value: Any) -> str: # statement looking for any of the values. If there is only a single # value, then we have to return a normal "contains" statement using # the only item in the list. - if isinstance(value, list): + if isinstance(value, list) and len(value) > 0: if len(value) > 1: operator = 'in' vals = [f'"{str(i)}"' for i in value]