diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 2881b52b94..6d2d0d60f9 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1775,13 +1775,14 @@ class JobLaunchSerializer(BaseSerializer): passwords = self.context.get('passwords') data = self.context.get('data') + credential = attrs.get('credential', None) or obj.credential # fill passwords dict with request data passwords - if obj.passwords_needed_to_start: + if credential.passwords_needed: try: - for p in obj.passwords_needed_to_start: - passwords[p] = data.get(p) + for p in credential.passwords_needed: + passwords[p] = data[p] except KeyError: - raise serializers.ValidationError(obj.passwords_needed_to_start) + raise serializers.ValidationError(credential.passwords_needed) return attrs def validate(self, attrs): diff --git a/awx/main/models/ad_hoc_commands.py b/awx/main/models/ad_hoc_commands.py index d3dce392d2..ffeb90522c 100644 --- a/awx/main/models/ad_hoc_commands.py +++ b/awx/main/models/ad_hoc_commands.py @@ -114,7 +114,7 @@ class AdHocCommand(UnifiedJob): @property def passwords_needed_to_start(self): '''Return list of password field names needed to start the job.''' - if self.credential: + if self.credential and self.credential.active: return self.credential.passwords_needed else: return [] diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 0ab8d0ee67..df7b96eeef 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -141,7 +141,7 @@ class JobOptions(BaseModel): @property def passwords_needed_to_start(self): '''Return list of password field names needed to start the job.''' - if self.credential: + if self.credential and self.credential.active: return self.credential.passwords_needed else: return []