1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 23:51:09 +03:00

Merge pull request #2906 from AlanCoding/2875_old_launch

Fix old method of launching jobs by directly raising validation errors
This commit is contained in:
Alan Rominger 2016-07-11 12:46:23 -04:00 committed by GitHub
commit c8b8cdf7f5

View File

@ -1926,12 +1926,11 @@ class JobSerializer(UnifiedJobSerializer, JobOptionsSerializer):
def to_internal_value(self, data):
# When creating a new job and a job template is specified, populate any
# fields not provided in data from the job template.
if not self.instance and isinstance(data, dict) and 'job_template' in data:
if not self.instance and isinstance(data, dict) and data.get('job_template', False):
try:
job_template = JobTemplate.objects.get(pk=data['job_template'])
except JobTemplate.DoesNotExist:
self._errors = {'job_template': 'Invalid job template.'}
return
raise serializers.ValidationError({'job_template': 'Invalid job template.'})
data.setdefault('name', job_template.name)
data.setdefault('description', job_template.description)
data.setdefault('job_type', job_template.job_type)
@ -2694,8 +2693,7 @@ class TowerSettingsSerializer(BaseSerializer):
def to_internal_value(self, data):
if data['key'] not in settings.TOWER_SETTINGS_MANIFEST:
self._errors = {'key': 'Key {0} is not a valid settings key.'.format(data['key'])}
return
raise serializers.ValidationError({'key': ['Key {0} is not a valid settings key.'.format(data['key'])]})
ret = super(TowerSettingsSerializer, self).to_internal_value(data)
manifest_val = settings.TOWER_SETTINGS_MANIFEST[data['key']]
ret['description'] = manifest_val['description']