Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serialize Workflow Job Template inventories by natural key - related #7798 #7805

Closed

Conversation

zedr
Copy link

@zedr zedr commented Aug 3, 2020

SUMMARY

Related #7798

This changeset introduces two changes:

  1. Update the API representation of Workflow Job Templates to use the
    natural key of the Inventory type instead of its id;
  2. Override the related property of the CLI's WorkflowJobTemplate page
    type to patch the related references during the export process,
    allowing the resource to be serialised using the natural key of the
    Inventory type instead of the id.

Change n.2 is a workaround that is used when exporting resources from
AWX/Tower instances that don't have change n.1. It can be removed in the
future.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
  • API
  • CLI
AWX VERSION
awx: 13.0.0

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

…nsible#7798

This changeset introduces two changes:

 1. Update the API representation of Workflow Job Templates to use the
 natural key of the Inventory type instead of its id;
 2. Override the related property of the CLI's WorkflowJobTemplate page
 type to patch the related references during the export process,
 allowing the resource to be serialised using the natural key of the
 Inventory type instead of the id.

Change n.2 is a workaround that is used when exporting resources from
AWX/Tower instances that don't have change n.1. It can be removed in the
future.
@zedr zedr force-pushed the fix-workflow-inventories-by-natural-key branch from ad0c9f1 to 5238d72 Compare August 4, 2020 09:02
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -15,6 +15,27 @@ class WorkflowJobTemplate(HasCopy, HasCreate, HasNotifications, HasSurvey, Unifi
optional_dependencies = [Organization]
NATURAL_KEY = ('organization', 'name')

@property
def related(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty uncomfortable with doing it this way. However, fortunately, I do note that the inventory field shows up as of type 'id' in the OPTIONS call on the api endpoint even under current devel awx. I think it would be easy enough to check for the case of an id field that fails to show up in related in the _export() method, and attempt to construct the natural key by other means (probably by doing a _filtered_list() call).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Good suggestion. I'll look into it and push an update if I get something working.

@jbradberry
Copy link
Contributor

I've gone ahead and rebased this branch against the latest devel, and made the change I recommended. The new PR is #8353.

@jbradberry jbradberry closed this Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants