diff --git a/awx/api/serializers.py b/awx/api/serializers.py index be6a9d640b9d..f97548be3039 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -3404,6 +3404,12 @@ def get_related(self, obj): res['organization'] = self.reverse('api:organization_detail', kwargs={'pk': obj.organization.pk}) if obj.webhook_credential_id: res['webhook_credential'] = self.reverse('api:credential_detail', kwargs={'pk': obj.webhook_credential_id}) + if obj.inventory: + res['inventory'] = self.reverse( + 'api:inventory_detail', kwargs={ + 'pk': obj.inventory.pk + } + ) return res def validate_extra_vars(self, value): diff --git a/awxkit/awxkit/api/pages/workflow_job_templates.py b/awxkit/awxkit/api/pages/workflow_job_templates.py index 17f3b5634273..c134196dca1c 100644 --- a/awxkit/awxkit/api/pages/workflow_job_templates.py +++ b/awxkit/awxkit/api/pages/workflow_job_templates.py @@ -15,6 +15,27 @@ class WorkflowJobTemplate(HasCopy, HasCreate, HasNotifications, HasSurvey, Unifi optional_dependencies = [Organization] NATURAL_KEY = ('organization', 'name') + @property + def related(self): + """Augment the related namespace with the inventory. + + This provides a workaround for API instances that do not provide + a reference to this workflow's associated inventory, if defined, + in the related namespace. + + See issue #7798. + """ + related_data = self.__getattr__('related') + if 'inventory' not in related_data: + inventory_id = self.json['inventory'] + if inventory_id: + endpoint_url = '/api/v2/inventories/{}/'.format(inventory_id) + related_data['inventory'] = page.TentativePage( + endpoint_url, + self.connection + ) + return related_data + def launch(self, payload={}): """Launch using related->launch endpoint.""" # get related->launch