1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

fix WARNING log when launching ad hoc command

This commit is contained in:
AlanCoding 2017-10-05 13:42:23 -04:00
parent eacbeef660
commit 81c14ce942
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
2 changed files with 11 additions and 17 deletions

View File

@ -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

View File

@ -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