mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 18:37:36 -02:30
Use consistent error message when vars are not parsed correctly
This commit is contained in:
@@ -1216,7 +1216,7 @@ class HostSerializer(BaseSerializerWithVariables):
|
|||||||
vars_dict['ansible_ssh_port'] = port
|
vars_dict['ansible_ssh_port'] = port
|
||||||
attrs['variables'] = yaml.dump(vars_dict)
|
attrs['variables'] = yaml.dump(vars_dict)
|
||||||
except (yaml.YAMLError, TypeError):
|
except (yaml.YAMLError, TypeError):
|
||||||
raise serializers.ValidationError(_('Must be valid JSON or YAML.'))
|
raise serializers.ValidationError({'variables': _('Must be valid JSON or YAML.')})
|
||||||
|
|
||||||
return super(HostSerializer, self).validate(attrs)
|
return super(HostSerializer, self).validate(attrs)
|
||||||
|
|
||||||
@@ -2693,7 +2693,7 @@ class JobLaunchSerializer(BaseSerializer):
|
|||||||
extra_vars = yaml.safe_load(extra_vars)
|
extra_vars = yaml.safe_load(extra_vars)
|
||||||
assert isinstance(extra_vars, dict)
|
assert isinstance(extra_vars, dict)
|
||||||
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
||||||
errors['extra_vars'] = _('Must be a valid JSON or YAML dictionary.')
|
errors['extra_vars'] = _('Must be valid JSON or YAML.')
|
||||||
|
|
||||||
if not isinstance(extra_vars, dict):
|
if not isinstance(extra_vars, dict):
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
@@ -2764,7 +2764,7 @@ class WorkflowJobLaunchSerializer(BaseSerializer):
|
|||||||
extra_vars = yaml.safe_load(extra_vars)
|
extra_vars = yaml.safe_load(extra_vars)
|
||||||
assert isinstance(extra_vars, dict)
|
assert isinstance(extra_vars, dict)
|
||||||
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
except (yaml.YAMLError, TypeError, AttributeError, AssertionError):
|
||||||
errors['extra_vars'] = 'Must be a valid JSON or YAML dictionary.'
|
errors['extra_vars'] = _('Must be valid JSON or YAML.')
|
||||||
|
|
||||||
if not isinstance(extra_vars, dict):
|
if not isinstance(extra_vars, dict):
|
||||||
extra_vars = {}
|
extra_vars = {}
|
||||||
|
|||||||
@@ -196,7 +196,8 @@ def test_job_reject_invalid_prompted_extra_vars(runtime_data, job_template_promp
|
|||||||
reverse('api:job_template_launch', args=[job_template.pk]),
|
reverse('api:job_template_launch', args=[job_template.pk]),
|
||||||
dict(extra_vars='{"unbalanced brackets":'), admin_user, expect=400)
|
dict(extra_vars='{"unbalanced brackets":'), admin_user, expect=400)
|
||||||
|
|
||||||
assert response.data['extra_vars'] == ['Must be a valid JSON or YAML dictionary.']
|
assert 'extra_vars' in response.data
|
||||||
|
assert 'valid JSON or YAML' in str(response.data['extra_vars'][0])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
|
|||||||
Reference in New Issue
Block a user