diff --git a/flask_log_request_id/__init__.py b/flask_log_request_id/__init__.py index 23accbd..30b6c12 100644 --- a/flask_log_request_id/__init__.py +++ b/flask_log_request_id/__init__.py @@ -4,7 +4,7 @@ from . import parser -__version__ = '0.9.3' +__version__ = '0.9.4' __all__ = [ diff --git a/flask_log_request_id/request_id.py b/flask_log_request_id/request_id.py index 695a61c..9f38ea0 100644 --- a/flask_log_request_id/request_id.py +++ b/flask_log_request_id/request_id.py @@ -81,7 +81,7 @@ def _persist_request_id(): setattr(g, g_object_attr, self._request_id_generator()) # Register after request - if self.app.config['LOG_REQUEST_ID_LOG_ALL_REQUESTS']: + if app.config['LOG_REQUEST_ID_LOG_ALL_REQUESTS']: app.after_request(self._log_http_event) @staticmethod diff --git a/tests/request_id_tests.py b/tests/request_id_tests.py index b1c0d5c..fc61a77 100644 --- a/tests/request_id_tests.py +++ b/tests/request_id_tests.py @@ -12,6 +12,14 @@ def setUp(self): self.app.route('/')(lambda: 'hello world') self.app.testing = True + def test_lazy_initialization(self): + # Bug #38: https://github.com/Workable/flask-log-request-id/issues/38 + request_id = RequestID() + request_id.init_app(self.app) + with self.app.test_request_context(headers={'X-Amzn-Trace-Id': 'Self=1-67891234-def;Root=1-67891233-abc'}): + self.app.preprocess_request() + self.assertEqual('1-67891234-def', current_request_id()) + def test_default_request_id_parser_with_amazon(self): RequestID(self.app) with self.app.test_request_context(headers={'X-Amzn-Trace-Id': 'Self=1-67891234-def;Root=1-67891233-abc'}):