From 71318e5d9a7a5de0e6a6c77dcd1043991e3f42c7 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Fri, 20 Feb 2015 15:37:53 -0500 Subject: [PATCH] don't try and decode extra_vars if there are no extra_vars. Further, if extra_vars isn't a json, then don't try to redact. --- awx/api/serializers.py | 14 +++++++++----- awx/main/tests/jobs/survey_password.py | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index cc23e13a8e..ff4d241f04 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1422,11 +1422,15 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer): ret['job_template'] = None if obj.job_template and obj.job_template.survey_enabled: - extra_vars = json.loads(ret['extra_vars']) - for key in obj.job_template.survey_password_variables(): - if key in extra_vars: - extra_vars[key] = REPLACE_STR - ret['extra_vars'] = json.dumps(extra_vars) + if ret['extra_vars']: + try: + extra_vars = json.loads(ret['extra_vars']) + for key in obj.job_template.survey_password_variables(): + if key in extra_vars: + extra_vars[key] = REPLACE_STR + ret['extra_vars'] = json.dumps(extra_vars) + except ValueError: + pass return ret diff --git a/awx/main/tests/jobs/survey_password.py b/awx/main/tests/jobs/survey_password.py index 74b7d67ae5..c5243712b5 100644 --- a/awx/main/tests/jobs/survey_password.py +++ b/awx/main/tests/jobs/survey_password.py @@ -6,7 +6,7 @@ from django.core.urlresolvers import reverse # AWX from awx.main.models import * # noqa -from awx.main.tests.base import BaseTest +from awx.main.tests.base import BaseTest, QueueStartStopTestMixin __all__ = ['SurveyPasswordRedactedTest'] @@ -141,7 +141,7 @@ TESTS = { } } -class SurveyPasswordBaseTest(BaseTest): +class SurveyPasswordBaseTest(BaseTest, QueueStartStopTestMixin): def setUp(self): super(SurveyPasswordBaseTest, self).setUp() self.setup_instances()