From fd9d05d5df2b85e78fd3ed6749f2f2ef545d200e Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Tue, 30 Aug 2016 14:21:16 -0400 Subject: [PATCH] fixing deprecated_team.organization credential migration --- awx/main/fields.py | 8 ++------ awx/main/migrations/_rbac.py | 9 ++++++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/awx/main/fields.py b/awx/main/fields.py index 92ed69672f..e95dbc1ee7 100644 --- a/awx/main/fields.py +++ b/awx/main/fields.py @@ -54,10 +54,6 @@ class AutoOneToOneField(models.OneToOneField): AutoSingleRelatedObjectDescriptor(related)) - - - - def resolve_role_field(obj, field): ret = [] @@ -71,8 +67,8 @@ def resolve_role_field(obj, field): return [] if len(field_components) == 1: - Role_ = get_current_apps().get_model('main', 'Role') - if type(obj) is not Role_: + role_cls = str(get_current_apps().get_model('main', 'Role')) + if not str(type(obj)) == role_cls: raise Exception(smart_text('{} refers to a {}, not a Role'.format(field, type(obj)))) ret.append(obj.id) else: diff --git a/awx/main/migrations/_rbac.py b/awx/main/migrations/_rbac.py index 245adc58ef..80ecc69ebc 100644 --- a/awx/main/migrations/_rbac.py +++ b/awx/main/migrations/_rbac.py @@ -2,7 +2,9 @@ import logging from time import time from django.utils.encoding import smart_text +from django.db import transaction from django.db.models import Q +from django.db.utils import IntegrityError from collections import defaultdict from awx.main.utils import getattrd @@ -489,7 +491,12 @@ def rebuild_role_hierarchy(apps, schema_editor): logger.info('Rebuild completed in %f seconds' % (stop - start)) logger.info('Done.') + def infer_credential_org_from_team(apps, schema_editor): Credential = apps.get_model('main', "Credential") for cred in Credential.objects.exclude(deprecated_team__isnull=True): - _update_credential_parents(cred.deprecated_team.organization, cred) + try: + with transaction.atomic(): + _update_credential_parents(cred.deprecated_team.organization, cred) + except IntegrityError: + logger.info("Organization<{}> credential for old Team<{}> credential already created".format(cred.deprecated_team.organization.pk, cred.pk))