From 81c14ce9428accc05850bd4b3ed8c34394a91e93 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 5 Oct 2017 13:42:23 -0400 Subject: [PATCH] fix WARNING log when launching ad hoc command --- awx/main/models/unified_jobs.py | 22 +++++++--------------- awx/main/utils/common.py | 6 ++++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/awx/main/models/unified_jobs.py b/awx/main/models/unified_jobs.py index e148d45862..91285ecc16 100644 --- a/awx/main/models/unified_jobs.py +++ b/awx/main/models/unified_jobs.py @@ -34,7 +34,7 @@ from awx.main.models.mixins import ResourceMixin, TaskManagerUnifiedJobMixin from awx.main.utils import ( decrypt_field, _inventory_updates, copy_model_by_class, copy_m2m_relationships, - get_type_for_model + get_type_for_model, parse_yaml_or_json ) from awx.main.redact import UriCleaner, REPLACE_STR from awx.main.consumers import emit_channel_notification @@ -878,21 +878,13 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique return [] def handle_extra_data(self, extra_data): - if hasattr(self, 'extra_vars'): - extra_vars = {} - if isinstance(extra_data, dict): - extra_vars = extra_data - elif extra_data is None: - return - else: - if extra_data == "": - return - try: - extra_vars = json.loads(extra_data) - except Exception as e: - logger.warn("Exception deserializing extra vars: " + str(e)) + if hasattr(self, 'extra_vars') and extra_data: + try: + extra_data_dict = parse_yaml_or_json(extra_data, silent_failure=False) + except Exception as e: + logger.warn("Exception deserializing extra vars: " + str(e)) evars = self.extra_vars_dict - evars.update(extra_vars) + evars.update(extra_data_dict) self.update_fields(extra_vars=json.dumps(evars)) @property diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 15d3388bdc..22183c33dd 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -581,7 +581,7 @@ def cache_list_capabilities(page, prefetch_list, model, user): obj.capabilities_cache[display_method] = True -def parse_yaml_or_json(vars_str): +def parse_yaml_or_json(vars_str, silent_failure=True): ''' Attempt to parse a string with variables, and if attempt fails, return an empty dictionary. @@ -595,7 +595,9 @@ def parse_yaml_or_json(vars_str): vars_dict = yaml.safe_load(vars_str) assert isinstance(vars_dict, dict) except (yaml.YAMLError, TypeError, AttributeError, AssertionError): - vars_dict = {} + if silent_failure: + return {} + raise return vars_dict