Skip to content

Commit b6d380a

Browse files
authored
PynamoDB patcher bug fix (#72)
* Fixed a pynamodb patcher encoding bug under python3.4 and 3.5 * 1.1.2 release commit
1 parent 7ddbfbd commit b6d380a

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
CHANGELOG
33
=========
44

5+
1.1.2
6+
=====
7+
* bugfix: Fixed an issue on PynamoDB patcher where the capture didn't handle client timeout.
8+
59
1.1.1
610
=====
711
* bugfix: Handle Aiohttp Exceptions as valid responses `PR59 <https://github.com/aws/aws-xray-sdk-python/pull/59>`_.

aws_xray_sdk/ext/pynamodb/patch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,24 @@ def pynamodb_meta_processor(wrapped, instance, args, kwargs, return_value,
4242
exception, subsegment, stack):
4343
operation_name = args[0].headers['X-Amz-Target'].decode('utf-8').split('.')[1]
4444
region = args[0].url.split('.')[1]
45-
request_id = return_value.headers.get('x-amzn-RequestId')
4645

4746
aws_meta = {
4847
'operation': operation_name,
49-
'request_id': request_id,
5048
'region': region
5149
}
5250

51+
# in case of client timeout the return value will be empty
52+
if return_value is not None:
53+
aws_meta['request_id'] = return_value.headers.get('x-amzn-RequestId')
54+
subsegment.put_http_meta(http.STATUS, return_value.status_code)
55+
5356
if exception:
5457
subsegment.add_error_flag()
5558
subsegment.add_exception(exception, stack, True)
5659

57-
subsegment.put_http_meta(http.STATUS, return_value.status_code)
58-
60+
resp = return_value.json() if return_value else None
5961
_extract_whitelisted_params(subsegment.name, operation_name, aws_meta,
6062
[None, json.loads(args[0].body.decode('utf-8'))],
61-
None, return_value.json())
63+
None, resp)
6264

6365
subsegment.set_aws(aws_meta)

aws_xray_sdk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '1.1.1'
1+
VERSION = '1.1.2'

tests/ext/pynamodb/test_pynamodb.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,29 @@ class Meta:
5454
assert aws_meta['table_name'] == 'mytable'
5555

5656

57+
def test_empty_response():
58+
from aws_xray_sdk.ext.pynamodb.patch import pynamodb_meta_processor
59+
subsegment = xray_recorder.begin_subsegment('test')
60+
61+
class TempReq(object):
62+
def __init__(self):
63+
self.headers = {'X-Amz-Target': 'ddb.ListTables'.encode('utf-8')}
64+
self.url = 'ddb.us-west-2'
65+
self.body = '{}'.encode('utf-8')
66+
67+
prepared_request = TempReq()
68+
args = [prepared_request]
69+
70+
pynamodb_meta_processor(wrapped=None, instance=None, args=args,
71+
kwargs=None, return_value=None,
72+
exception=None, subsegment=subsegment,
73+
stack=None)
74+
75+
aws_meta = subsegment.aws
76+
assert aws_meta['region'] == 'us-west-2'
77+
assert aws_meta['operation'] == 'ListTables'
78+
79+
5780
def test_only_dynamodb_calls_are_traced():
5881
"""Test only a single subsegment is created for other AWS services.
5982

0 commit comments

Comments
 (0)