From fccd6a22864bf5ac7cb458c693debb1fd12e37b6 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 3 Oct 2019 12:07:43 -0400 Subject: [PATCH] attempt to properly map more foreign keys to named lookups this is imperfect, but it's at least an improvement until we can come up with a better solution in order to really do this right, the API itself probably needs to grow some more metadata that allows us to specify *actual* `type`s that relate to API resources see: https://github.com/ansible/awx/issues/4874 --- awxkit/awxkit/cli/options.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/awxkit/awxkit/cli/options.py b/awxkit/awxkit/cli/options.py index 28a47fd06e..858808ae8e 100644 --- a/awxkit/awxkit/cli/options.py +++ b/awxkit/awxkit/cli/options.py @@ -40,6 +40,11 @@ def pk_or_name(v2, model_name, value, page=None): if model_name in UNIQUENESS_RULES: identity = UNIQUENESS_RULES[model_name][-1] + # certain related fields follow a pattern of _ e.g., + # insights_credential, target_credential etc... + if not page and '_' in model_name: + return pk_or_name(v2, model_name.split('_')[-1], value, page) + if page: results = page.get(**{identity: value}) if results.count == 1: