Skip to content

Commit 95b0c80

Browse files
committed
Ignore case when model can not be looked up in type creation
1 parent 58a1b55 commit 95b0c80

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ansible_base/rbac/management/create_types.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ def create_DAB_contenttypes(
7979
# Update, or set for the first time, the parent type reference
8080
updated_ct = 0
8181
for ct in dab_ct_cls.objects.all():
82-
ct_model_class = model_class(apps, ct)
82+
try:
83+
ct_model_class = model_class(apps, ct)
84+
except LookupError:
85+
logger.warning(f'Model {ct.model} is in the permission_registry but not in the current app state. ' 'This could be okay in reverse migrations.')
86+
continue
8387
if issubclass(ct_model_class, RemoteObject):
8488
continue # remote types not managed here
8589
if not permission_registry.is_registered(ct_model_class):

test_app/tests/rbac/test_managed.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ def test_courtesy_roles_pass_validation():
1414
if '_base' in template_name:
1515
continue # abstract, not intended to be used
1616
constructor = cls()
17-
perm_list = [DABPermission.objects.get(codename=str_perm) for str_perm in constructor.get_permissions(apps)]
17+
perm_list = []
18+
for str_perm in constructor.get_permissions(apps):
19+
if '.' in str_perm:
20+
perm_list.append(DABPermission.objects.get(api_slug=str_perm))
21+
else:
22+
perm_list.append(DABPermission.objects.get(codename=str_perm))
1823
model_cls = constructor.get_model(apps)
1924
if model_cls is not None:
2025
ct = permission_registry.content_type_model.objects.get_for_model(constructor.get_model(apps))

0 commit comments

Comments
 (0)