1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

monkey-patch get_current_apps so that resolve_role_field works correctly

This commit is contained in:
Wayne Witzel III 2017-06-15 11:00:20 -04:00
parent adc371fcf8
commit 2c1a39233e

View File

@ -1,3 +1,4 @@
from awx.main import utils
from awx.conf.migrations._reencrypt import decrypt_field from awx.conf.migrations._reencrypt import decrypt_field
@ -23,8 +24,13 @@ def _notification_templates(apps):
def _credentials(apps): def _credentials(apps):
Credential = apps.get_model('main', 'Credential') # this monkey-patch is necessary to make the implicit role generation save
for credential in Credential.objects.all(): # 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(): for field_name, value in credential.inputs.items():
if field_name in credential.credential_type.inputs.get('fields', []): if field_name in credential.credential_type.inputs.get('fields', []):
value = getattr(credential, field_name) value = getattr(credential, field_name)
@ -34,6 +40,9 @@ def _credentials(apps):
value = decrypt_field(credential, field_name) value = decrypt_field(credential, field_name)
credential.inputs[field_name] = value credential.inputs[field_name] = value
credential.save() credential.save()
finally:
utils.get_current_apps = orig_current_apps
def _unified_jobs(apps): def _unified_jobs(apps):