diff --git a/awx/api/generics.py b/awx/api/generics.py index 3657505a46..b10728f32a 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -214,8 +214,15 @@ class APIView(views.APIView): 'user_name': request.user, 'url_path': request.path, 'remote_addr': request.META.get('REMOTE_ADDR', None), - 'error': response.data.get('error', response.status_text), } + + if type(response.data) is dict: + msg_data['error'] = response.data.get('error', response.status_text) + elif type(response.data) is list: + msg_data['error'] = ", ".join(list(map(lambda x: x.get('error', response.status_text), response.data))) + else: + msg_data['error'] = response.status_text + try: status_msg = getattr(settings, 'API_400_ERROR_LOG_FORMAT').format(**msg_data) except Exception as e: diff --git a/awx/main/tests/functional/test_api_generics.py b/awx/main/tests/functional/test_api_generics.py index 4733c26768..029413af51 100644 --- a/awx/main/tests/functional/test_api_generics.py +++ b/awx/main/tests/functional/test_api_generics.py @@ -24,3 +24,8 @@ def test_custom_400_error_log(caplog, post, admin_user): with override_settings(API_400_ERROR_LOG_FORMAT="{status_code} {error}"): post(url=reverse('api:setting_logging_test'), data={}, user=admin_user, expect=409) assert '409 Logging not enabled' in caplog.text + + +# The above tests the generation function with a dict/object. +# The tower-qa test tests.api.inventories.test_inventory_update.TestInventoryUpdate.test_update_all_inventory_sources_with_nonfunctional_sources tests the function with a list +# Someday it would be nice to test the else condition (not a dict/list) but we need to find an API test which will do this. For now it was added just as a catch all