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

def _deserialize_n(self, value: str) -> Decimal:
# value is None or "."? It's zero
# then return early
value = value.lstrip("0")
if not value or value == ".":
return DYNAMODB_CONTEXT.create_decimal(0)

if len(value) > 38:
# See: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.NamingRulesDataTypes.html#HowItWorks.DataTypes.Number
# Calculate the number of trailing zeros after the 38th character
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,22 @@ def test_dynamodb_stream_record_deserialization_large_int_without_trailing_zeros
}


def test_dynamodb_stream_record_deserialization_zero_value():

data = {
"Keys": {"key1": {"attr1": "value1"}},
"NewImage": {
"Name": {"S": "Joe"},
"Age": {"N": "0"},
},
}
record = StreamRecord(data)
assert record.new_image == {
"Name": "Joe",
"Age": DECIMAL_CONTEXT.create_decimal("0"),
}


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