-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(data_class): ensure DynamoDBStreamEvent conforms to decimal limits (
#4863) * fix(utilities): DDB Large numbers Signed-off-by: Simon Thulbourn <sthulb@users.noreply.github.com> * rename var * add unit test for large numbers * remove leading 0s too * Small refactor --------- Signed-off-by: Simon Thulbourn <sthulb@users.noreply.github.com> Co-authored-by: Leandro Damascena <lcdama@amazon.pt>
- Loading branch information
1 parent
4d249ac
commit f763d0f
Showing
2 changed files
with
46 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,14 @@ def _deserialize_bool(self, value: bool) -> bool: | |
return value | ||
|
||
def _deserialize_n(self, value: str) -> Decimal: | ||
value = value.lstrip("0") | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
arielbeckjit
|
||
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 | ||
tail = len(value[38:]) - len(value[38:].rstrip("0")) | ||
# Trim the value: remove trailing zeros if any, or just take the first 38 characters | ||
value = value[:-tail] if tail > 0 else value[:38] | ||
|
||
return DYNAMODB_CONTEXT.create_decimal(value) | ||
|
||
def _deserialize_s(self, value: str) -> str: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@sthulb are you sure this did not introduce a bug?
i'm seeing
{ "N": "0"}
parsed as NaN because the 0 is removed to a{"N": ""}