mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Remove the NoNaturalKey error
It's too awkward, and it makes more sense to return None instead.
This commit is contained in:
parent
e053a58223
commit
ab15349c8c
@ -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):
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -106,8 +106,3 @@ class IsMigrating(Common):
|
||||
class ImportExportError(Exception):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class NoNaturalKey(ImportExportError):
|
||||
|
||||
pass
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user