Preserving original debug for query debugging.

This commit is contained in:
Samuel Clay 2021-02-08 12:12:00 -05:00
parent 8484ec9f71
commit fe54785a9c
2 changed files with 16 additions and 4 deletions

View file

@ -45,6 +45,7 @@ class DBProfilerMiddleware:
random.random() < .01):
request.activated_segments.append('db_profiler')
connection.use_debug_cursor = True
setattr(settings, 'ORIGINAL_DEBUG', settings.DEBUG)
settings.DEBUG = True
def process_celery(self):
@ -52,6 +53,7 @@ class DBProfilerMiddleware:
if random.random() < .01:
self.activated_segments.append('db_profiler')
connection.use_debug_cursor = True
setattr(settings, 'ORIGINAL_DEBUG', settings.DEBUG)
settings.DEBUG = True
return self
@ -136,14 +138,18 @@ class SQLLogToConsoleMiddleware:
'redis': sum([float(q['time']) for q in queries if q.get('redis')]),
}
setattr(request, 'sql_times_elapsed', times_elapsed)
settings.DEBUG = False
else:
print(" ***> No queries")
if not getattr(settings, 'ORIGINAL_DEBUG', settings.DEBUG):
settings.DEBUG = False
return response
def process_celery(self, profiler):
self.process_response(profiler, None)
settings.DEBUG = False
if not getattr(settings, 'ORIGINAL_DEBUG', settings.DEBUG):
settings.DEBUG = False
SIMPSONS_QUOTES = [
("Homer", "D'oh."),

8
fabfile.py vendored
View file

@ -817,11 +817,17 @@ def assemble_certificates():
local('pwd')
local('cat STAR_newsblur_com.crt EssentialSSLCA_2.crt ComodoUTNSGCCA.crt UTNAddTrustSGCCA.crt AddTrustExternalCARoot.crt > newsblur.com.crt')
def copy_certificates():
def copy_certificates(copy=False):
cert_path = os.path.join(env.NEWSBLUR_PATH, 'config/certificates')
run('mkdir -p %s' % cert_path)
fullchain_path = "/etc/letsencrypt/live/newsblur.com/fullchain.pem"
privkey_path = "/etc/letsencrypt/live/newsblur.com/privkey.pem"
if copy:
sudo('mkdir -p %s' % os.path.dirname(fullchain_path))
put(os.path.join(env.SECRETS_PATH, 'certificates/newsblur.com.pem'), fullchain_path, use_sudo=True)
put(os.path.join(env.SECRETS_PATH, 'certificates/newsblur.com.key'), privkey_path, use_sudo=True)
run('ln -fs %s %s' % (fullchain_path, os.path.join(cert_path, 'newsblur.com.crt')))
run('ln -fs %s %s' % (fullchain_path, os.path.join(cert_path, 'newsblur.com.pem'))) # For backwards compatibility with hard-coded nginx configs
run('ln -fs %s %s' % (privkey_path, os.path.join(cert_path, 'newsblur.com.key')))