Skip to content

Commit

Permalink
Merge pull request #40 from nvllsvm/cor
Browse files Browse the repository at this point in the history
Fix exception when correlation_id is None
  • Loading branch information
dave-shawley committed Mar 7, 2022
2 parents e0e6736 + 37dc95c commit 89b6ebf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sprockets/mixins/http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def _http_req_apply_default_headers(self, request_headers, content_type,
request_headers.setdefault(
'Content-Type',
str(content_type) or str(CONTENT_TYPE_MSGPACK))
if hasattr(self, 'correlation_id'):
if hasattr(self, 'correlation_id') and self.correlation_id:
request_headers.setdefault('Correlation-Id', self.correlation_id)
elif hasattr(self, 'request') and \
self.request.headers.get('Correlation-Id'):
Expand Down
10 changes: 10 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,16 @@ def test_without_correlation_id_behavior(self):
self.assertEqual(response.code, 502)
self.assertEqual(response.attempts, 3)

@testing.gen_test
def test_correlation_id_is_none(self):
mixin = self.create_mixin()
mixin.correlation_id = None
response = yield mixin.http_fetch(
self.get_url('/error?status_code=502'))
self.assertFalse(response.ok)
self.assertEqual(response.code, 502)
self.assertEqual(response.attempts, 3)

@testing.gen_test
def test_get(self):
response = yield self.mixin.http_fetch(
Expand Down

0 comments on commit 89b6ebf

Please sign in to comment.