Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions flask_log_request_id/request_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ def flask_ctx_get_request_id():
Get request id from flask's G object
:return: The id or None if not found.
"""
from flask import _app_ctx_stack as stack # We do not support < Flask 0.9

if stack.top is None:
raise ExecutedOutsideContext()

g_object_attr = stack.top.app.config['LOG_REQUEST_ID_G_OBJECT_ATTRIBUTE']
return g.get(g_object_attr, None)
if flask.has_app_context():
g_object_attr = g.log_request_id_g_object_attribute
return g.get(g_object_attr, None)


current_request_id = MultiContextRequestIdFetcher()
Expand Down Expand Up @@ -73,6 +69,7 @@ def _persist_request_id():

To be used as a consumer of Flask.before_request event.
"""
g.log_request_id_g_object_attribute = app.config['LOG_REQUEST_ID_G_OBJECT_ATTRIBUTE']
g_object_attr = current_app.config['LOG_REQUEST_ID_G_OBJECT_ATTRIBUTE']

setattr(g, g_object_attr, self._request_id_parser())
Expand Down