summaryrefslogtreecommitdiffstats
path: root/tools/scripts
diff options
context:
space:
mode:
authorJeff Bradberry <jeff.bradberry@gmail.com>2024-05-13 22:00:26 +0200
committerJeff Bradberry <jeff.bradberry@gmail.com>2024-06-10 22:36:22 +0200
commit31db6a1447994d943cdfd77091503003bb04ddc1 (patch)
tree1fff2a50b49d127ce9d0ffddb41845f675ecbe20 /tools/scripts
parentAdjusted foreignkeys.sql for correctness (diff)
downloadawx-31db6a1447994d943cdfd77091503003bb04ddc1.tar.xz
awx-31db6a1447994d943cdfd77091503003bb04ddc1.zip
Fix another instance where a bad resource->Role fk could throw a traceback
Diffstat (limited to 'tools/scripts')
-rw-r--r--tools/scripts/ig-hotfix/role_check.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/scripts/ig-hotfix/role_check.py b/tools/scripts/ig-hotfix/role_check.py
index 076f2e1b90..6ca653fc6c 100644
--- a/tools/scripts/ig-hotfix/role_check.py
+++ b/tools/scripts/ig-hotfix/role_check.py
@@ -45,7 +45,7 @@ for ct in ContentType.objects.order_by('id'):
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.")
+ sys.stderr.write(f"{cls} id={obj.id} {f.name} points to Role id={r_id}, which is not in the database.\n")
crosslinked[ct.id][obj.id][f'{f.name}_id'] = None
continue
if not r:
@@ -102,7 +102,12 @@ for r in Role.objects.exclude(role_field__startswith='system_').order_by('id'):
sys.stderr.write(f"Role id={r.id} has cross-linked parents: {plus}\n")
crosslinked_parents[r.id].extend(x.id for x in plus)
- rev = getattr(r.content_object, r.role_field, None)
+ try:
+ rev = getattr(r.content_object, r.role_field, None)
+ except Role.DoesNotExist:
+ sys.stderr.write(f"Role id={r.id} {r.content_type!r} {r.object_id} {r.role_field} points at an object with a broken role.\n")
+ crosslinked[r.content_type_id][r.object_id][f'{r.role_field}_id'] = r.id
+ continue
if rev is None or r.id != rev.id:
if rev and (r.content_type_id, r.object_id, r.role_field) == (rev.content_type_id, rev.object_id, rev.role_field):
sys.stderr.write(f"Role id={r.id} {r.content_type!r} {r.object_id} {r.role_field} is an orphaned duplicate of Role id={rev.id}, which is actually being used by the assigned resource\n")