From 2c1a39233e660b6db522bf148024121b47f86967 Mon Sep 17 00:00:00 2001 From: Wayne Witzel III Date: Thu, 15 Jun 2017 11:00:20 -0400 Subject: [PATCH] monkey-patch get_current_apps so that resolve_role_field works correctly --- awx/main/migrations/_reencrypt.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/awx/main/migrations/_reencrypt.py b/awx/main/migrations/_reencrypt.py index ae5dc5e76d..2aa1d2fbb0 100644 --- a/awx/main/migrations/_reencrypt.py +++ b/awx/main/migrations/_reencrypt.py @@ -1,3 +1,4 @@ +from awx.main import utils from awx.conf.migrations._reencrypt import decrypt_field @@ -23,17 +24,25 @@ def _notification_templates(apps): def _credentials(apps): - Credential = apps.get_model('main', 'Credential') - for credential in Credential.objects.all(): - for field_name, value in credential.inputs.items(): - if field_name in credential.credential_type.inputs.get('fields', []): - value = getattr(credential, field_name) - if value.startswith('$encrypted$AESCBC$'): - continue - elif value.startswith('$encrypted$AES$'): - value = decrypt_field(credential, field_name) - credential.inputs[field_name] = value - credential.save() + # this monkey-patch is necessary to make the implicit role generation save + # signal use the correct Role model (the version active at this point in + # migration, not the one at HEAD) + orig_current_apps = utils.get_current_apps + try: + utils.get_current_apps = lambda: apps + for credential in apps.get_model('main', 'Credential').objects.all(): + for field_name, value in credential.inputs.items(): + if field_name in credential.credential_type.inputs.get('fields', []): + value = getattr(credential, field_name) + if value.startswith('$encrypted$AESCBC$'): + continue + elif value.startswith('$encrypted$AES$'): + value = decrypt_field(credential, field_name) + credential.inputs[field_name] = value + credential.save() + finally: + utils.get_current_apps = orig_current_apps + def _unified_jobs(apps):