mirror of
https://github.com/ansible/awx.git
synced 2026-02-21 05:00:07 -03:30
Fix a problem with using PrimaryKeyRelatedField in our settings registry
DRF, when using this field, short-circuits the call to .to_representation() when the value is None, since clearly you aren't going to be able to get the .pk attribute off of it in that case. We were previously unconditionally calling .to_representation() which throws an error when we try to clear the value of DEFAULT_EXECUTION_ENVIRONMENT.
This commit is contained in:
@@ -23,6 +23,7 @@ import cachetools
|
|||||||
# AWX
|
# AWX
|
||||||
from awx.main.utils import encrypt_field, decrypt_field
|
from awx.main.utils import encrypt_field, decrypt_field
|
||||||
from awx.conf import settings_registry
|
from awx.conf import settings_registry
|
||||||
|
from awx.conf.fields import PrimaryKeyRelatedField
|
||||||
from awx.conf.models import Setting
|
from awx.conf.models import Setting
|
||||||
from awx.conf.migrations._reencrypt import decrypt_field as old_decrypt_field
|
from awx.conf.migrations._reencrypt import decrypt_field as old_decrypt_field
|
||||||
|
|
||||||
@@ -420,9 +421,9 @@ class SettingsWrapper(UserSettingsHolder):
|
|||||||
raise ImproperlyConfigured('Setting "{}" is read only.'.format(name))
|
raise ImproperlyConfigured('Setting "{}" is read only.'.format(name))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = field.to_representation(value)
|
data = None if value is None and isinstance(field, PrimaryKeyRelatedField) else field.to_representation(value)
|
||||||
setting_value = field.run_validation(data)
|
setting_value = field.run_validation(data)
|
||||||
db_value = field.to_representation(setting_value)
|
db_value = None if setting_value is None and isinstance(field, PrimaryKeyRelatedField) else field.to_representation(setting_value)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception('Unable to assign value "%r" to setting "%s".', value, name, exc_info=True)
|
logger.exception('Unable to assign value "%r" to setting "%s".', value, name, exc_info=True)
|
||||||
raise e
|
raise e
|
||||||
|
|||||||
Reference in New Issue
Block a user