mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Attempt to infer related pages on export when the link is missing
This commit is contained in:
parent
32c08a09c3
commit
a07dabae9e
@ -3438,10 +3438,10 @@ class WorkflowJobTemplateSerializer(JobTemplateMixin, LabelsListMixin, UnifiedJo
|
||||
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:
|
||||
if obj.inventory_id:
|
||||
res['inventory'] = self.reverse(
|
||||
'api:inventory_detail', kwargs={
|
||||
'pk': obj.inventory.pk
|
||||
'pk': obj.inventory_id
|
||||
}
|
||||
)
|
||||
return res
|
||||
|
||||
@ -72,10 +72,21 @@ class ApiV2(base.Base):
|
||||
}
|
||||
|
||||
for key in post_fields:
|
||||
if key not in _page.related:
|
||||
continue
|
||||
if key in _page.related:
|
||||
related = _page.related[key]
|
||||
else:
|
||||
if post_fields[key]['type'] == 'id' and _page.json.get(key) is not None:
|
||||
log.warning("Related link %r missing from %s, attempting to reconstruct endpoint.",
|
||||
key, _page.endpoint)
|
||||
resource = getattr(self, key, None)
|
||||
if resource is None:
|
||||
log.error("Unable to infer endpoint for %r on %s.", key, _page.endpoint)
|
||||
continue
|
||||
related = self._filtered_list(resource, _page.json[key]).results[0]
|
||||
else:
|
||||
continue
|
||||
|
||||
rel_endpoint = self._cache.get_page(_page.related[key])
|
||||
rel_endpoint = self._cache.get_page(related)
|
||||
if rel_endpoint is None: # This foreign key is unreadable
|
||||
if post_fields[key].get('required'):
|
||||
log.error("Foreign key %r export failed for object %s.", key, _page.endpoint)
|
||||
|
||||
@ -15,27 +15,6 @@ 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user