From d675207f997fd5b82e0b1e0e06be4eb89ebd8f7e Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Mon, 6 May 2024 13:47:35 -0400 Subject: Handle the case where a resource points to a Role which isn't in the db --- tools/scripts/ig-hotfix/role_check.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/scripts/ig-hotfix/role_check.py b/tools/scripts/ig-hotfix/role_check.py index ec8511dfd9..d290d9c15c 100644 --- a/tools/scripts/ig-hotfix/role_check.py +++ b/tools/scripts/ig-hotfix/role_check.py @@ -22,7 +22,13 @@ for ct in ContentType.objects.order_by('id'): for f in cls._meta.fields: if not isinstance(f, ImplicitRoleField): continue - r = getattr(obj, f.name, None) + r_id = getattr(obj, f'{f.name}_id', None) + try: + r = getattr(obj, f.name, None) + except Role.DoesNotExist: + sys.stderr.write(f"{cls} id={obj.id} {f.name} points to Role id={r_id}, which is not in the database.") + crosslinked[ct.id][obj.id][f'{f.name}_id'] = None + continue if not r: sys.stderr.write(f"{cls} id={obj.id} {f.name} does not have a Role object\n") crosslinked[ct.id][obj.id][f'{f.name}_id'] = None -- cgit v1.2.3