Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def _deserialize_bool(self, value: bool) -> bool:
return value

def _deserialize_n(self, value: str) -> Decimal:
if len(value) > 38:
tail = len(value[38:]) - len(value[38:].rstrip("0"))
value = value[:-tail]

return DYNAMODB_CONTEXT.create_decimal(value)

def _deserialize_s(self, value: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@ def test_dynamodb_stream_trigger_event():
assert dynamodb.stream_view_type == StreamViewType.NEW_AND_OLD_IMAGES


def test_dynamodb_stream_record_deserialization_large_int():
decimal_context = Context(
Emin=-128,
Emax=126,
prec=38,
traps=[Clamped, Overflow, Inexact, Rounded, Underflow],
)
data = {
"Keys": {"key1": {"attr1": "value1"}},
"NewImage": {
"Name": {"S": "Joe"},
"Age": {"N": "11011111111111111000000000000000000000000000000"},
},
}
record = StreamRecord(data)
assert record.new_image == {
"Name": "Joe",
"Age": decimal_context.create_decimal("11011111111111111000000000000000000000"),
}


def test_dynamodb_stream_record_deserialization():
byte_list = [s.encode("utf-8") for s in ["item1", "item2"]]
decimal_context = Context(
Expand Down