From ab15349c8c792863951763e35ecfe22543393cda Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Thu, 2 Apr 2020 10:49:59 -0400 Subject: [PATCH] Remove the NoNaturalKey error It's too awkward, and it makes more sense to return None instead. --- awxkit/awxkit/api/pages/page.py | 14 ++++++++------ awxkit/awxkit/api/pages/roles.py | 9 +++++++-- awxkit/awxkit/exceptions.py | 5 ----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/awxkit/awxkit/api/pages/page.py b/awxkit/awxkit/api/pages/page.py index 9effa8ef64..8913625b53 100644 --- a/awxkit/awxkit/api/pages/page.py +++ b/awxkit/awxkit/api/pages/page.py @@ -319,14 +319,16 @@ class Page(object): def get_natural_key(self): if not getattr(self, 'NATURAL_KEY', None): - raise exc.NoNaturalKey( - "Page does not have a natural key: {}".format(getattr(self, 'endpoint', repr(self.__class__))) - ) + return None + natural_key = {} for key in self.NATURAL_KEY: if key in self.related: - # FIXME: use caching by url - natural_key[key] = self.related[key].get().get_natural_key() + try: + # FIXME: use caching by url + natural_key[key] = self.related[key].get().get_natural_key() + except exc.Forbidden: + return None elif key in self: natural_key[key] = self[key] if not natural_key: @@ -395,7 +397,7 @@ class PageList(object): return self.__item_class__(self.connection).create(*a, **kw) def get_natural_key(self): - raise exc.NoNaturalKey + return None class TentativePage(str): diff --git a/awxkit/awxkit/api/pages/roles.py b/awxkit/awxkit/api/pages/roles.py index a08d670840..d93de4cad1 100644 --- a/awxkit/awxkit/api/pages/roles.py +++ b/awxkit/awxkit/api/pages/roles.py @@ -1,4 +1,6 @@ from awxkit.api.resources import resources +import awxkit.exceptions as exc + from . import base from . import page @@ -14,8 +16,11 @@ class Role(base.Base): if name not in ('users', 'teams') ] if related_objs: - # FIXME: use caching by url - natural_key['content_object'] = related_objs[0].get().get_natural_key() + try: + # FIXME: use caching by url + natural_key['content_object'] = related_objs[0].get().get_natural_key() + except exc.Forbidden: + return None return natural_key diff --git a/awxkit/awxkit/exceptions.py b/awxkit/awxkit/exceptions.py index 99d75c50d6..596720b59d 100644 --- a/awxkit/awxkit/exceptions.py +++ b/awxkit/awxkit/exceptions.py @@ -106,8 +106,3 @@ class IsMigrating(Common): class ImportExportError(Exception): pass - - -class NoNaturalKey(ImportExportError): - - pass