From bbfabd27794b36cf57427616751292fe886356e6 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Tue, 8 May 2018 09:44:23 -0400 Subject: [PATCH] include full stack trace for DB settings error --- awx/conf/settings.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/awx/conf/settings.py b/awx/conf/settings.py index 5770f9052d..2f7970ec2b 100644 --- a/awx/conf/settings.py +++ b/awx/conf/settings.py @@ -5,6 +5,8 @@ import logging import sys import threading import time +import StringIO +import traceback import six @@ -62,11 +64,19 @@ __all__ = ['SettingsWrapper', 'get_settings_to_cache', 'SETTING_CACHE_NOTSET'] def _log_database_error(): try: yield - except (ProgrammingError, OperationalError) as e: + except (ProgrammingError, OperationalError): if 'migrate' in sys.argv and get_tower_migration_version() < '310': logger.info('Using default settings until version 3.1 migration.') else: - logger.warning('Database settings are not available, using defaults (%s)', e, exc_info=True) + # Somewhat ugly - craming the full stack trace into the log message + # the available exc_info does not give information about the real caller + # TODO: replace in favor of stack_info kwarg in python 3 + sio = StringIO.StringIO() + traceback.print_stack(file=sio) + sinfo = sio.getvalue() + sio.close() + sinfo = sinfo.strip('\n') + logger.warning('Database settings are not available, using defaults, logged from:\n{}'.format(sinfo)) finally: pass