Skip to content
Closed
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
2 changes: 1 addition & 1 deletion boto3/dynamodb/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def _deserialize_bool(self, value):
return value

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

def _deserialize_s(self, value):
return value
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/dynamodb/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def test_deserialize_integer(self):

def test_deserialize_decimal(self):
assert self.deserializer.deserialize({'N': '1.25'}) == Decimal('1.25')
assert self.deserializer.deserialize({'N': '1.2500'}) == Decimal('1.25')
assert self.deserializer.deserialize({'N': '1234567891234560000000000000000000000000'}) == Decimal('1.23456789123456E+39')
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test uses a different number than the one mentioned in the linked issue (#4693). The issue reports 1234567895171680000000000000000000000000 but this test uses 1234567891234560000000000000000000000000. Consider adding a test case with the exact number from the issue to ensure it's properly fixed.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding test cases for additional edge cases with trailing zeros to ensure comprehensive coverage:

  • Numbers with trailing zeros after the decimal point (e.g., '1.2500')
  • Negative numbers with trailing zeros (e.g., '-1234567891234560000000000000000000000000')
  • Numbers already in scientific notation (e.g., '1.23E+39')
  • Very small numbers with trailing zeros (e.g., '0.00001000')

Copilot uses AI. Check for mistakes.
assert self.deserializer.deserialize({'N': '-1234567891234560000000000000000000000000'}) == Decimal('-1.23456789123456E+39')
assert self.deserializer.deserialize({'N': '1.23E+39'}) == Decimal('1.23E+39')

def test_deserialize_string(self):
assert self.deserializer.deserialize({'S': 'foo'}) == 'foo'
Expand Down