Skip to content

DynamoDB deserialization throws exception for big numbers #4693

Description

@rowanseymour

Describe the bug

This was previously reported at #2500 but that issue was closed and the actions bot recommends creating a new issue which references that.

A number like 1234567895171680000000000000000000000000 is valid in DynamoDB and we're happily persisting such numbers using the golang sdk. But boto3 blows up trying to fetch an item with such a number because it treats the zeros as significant digits.

DYNAMODB_CONTEXT = Context(
    Emin=-128,
    Emax=126,
    prec=38,
    traps=[Clamped, Overflow, Inexact, Rounded, Underflow],
)

...

def _deserialize_n(self, value):
    return DYNAMODB_CONTEXT.create_decimal(value)

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Numbers like 1234567895171680000000000000000000000000 are valid in DynamoDB and should be parseable by boto3

Current Behavior

Traceback (most recent call last):
  File "<console>", line 1, in <module>
decimal.Rounded: [<class 'decimal.Rounded'>]

Reproduction Steps

from boto3.dynamodb.types import DYNAMODB_CONTEXT

DYNAMODB_CONTEXT.create_decimal("1234567895171680000000000000000000000000")

Possible Solution

I think it could be fixed using normalize, i.e.

def _deserialize_n(self, value):
    return DYNAMODB_CONTEXT.create_decimal(Decimal(value).normalize())

Additional Information/Context

No response

SDK version used

1.42.23

Environment details (OS name and version, etc.)

MacOS and Ubuntu

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugThis issue is a confirmed bug.dynamodbp3This is a minor priority issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions