Skip to content

fix(data-classes): keep the value of large DynamoDB numbers - #8513

Merged
leandrodamascena merged 3 commits into
aws-powertools:developfrom
chiruu12:fix/dynamodb-number-magnitude
Oct 2, 2026
Merged

leandrodamascena merged 3 commits into
aws-powertools:developfrom
chiruu12:fix/dynamodb-number-magnitude

Conversation

@chiruu12

@chiruu12 chiruu12 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Issue number: closes #8512

Summary

Changes

_deserialize_n used to count characters and slice the string when a number was longer than 38. The minus sign and the decimal point were counted as digits, and removing trailing zeros by slicing changed the magnitude.

It now parses with Decimal(value). When the coefficient has more than 38 digits, it is normalized with a 38-digit context, which moves trailing zeros into the exponent. DYNAMODB_CONTEXT.create_decimal then accepts it without raising Rounded (#4845) and the value is unchanged. Numbers with 38 digits or fewer go through as before.

Tests:

  • New parametrized test in tests/unit/shared/test_dynamodb_deserializer.py covering a negative 38-digit number, a 38-digit decimal, the value from DynamoDBRecord throws decimal.Rounded for large numbers (over 38 digits) #4845 and a 38-digit number times 1000. All four fail on develop.
  • test_dynamodb_stream_record_deserialization_large_int asserted that a 47-digit number came back as a 38-digit one. Its expected value is now the original number.
  • test_dynamodb_stream_record_deserialization_large_int_without_trailing_zeros uses a value with more than 38 significant digits, which DynamoDB can't store. It now expects the number rounded to 38 digits at the same magnitude, instead of the first 38 characters.

User experience

Before:

>>> TypeDeserializer().deserialize({"N": "-12345678901234567890123456789012345678"})
Decimal('-1234567890123456789012345678901234567')

After:

>>> TypeDeserializer().deserialize({"N": "-12345678901234567890123456789012345678"})
Decimal('-12345678901234567890123456789012345678')

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@chiruu12
chiruu12 requested a review from a team as a code owner October 2, 2026 16:43
@chiruu12
chiruu12 requested review from leandrodamascena and a balanced review from Copilot October 2, 2026 16:43
@boring-cyborg

boring-cyborg Bot commented Oct 2, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 2, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 2, 2026
@codecov

codecov Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.92%. Comparing base (3311cc1) to head (130217c).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8513   +/-   ##
========================================
  Coverage    96.92%   96.92%           
========================================
  Files          317      317           
  Lines        15910    15911    +1     
  Branches      1398     1398           
========================================
+ Hits         15421    15422    +1     
  Misses         353      353           
  Partials       136      136           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sonarqubecloud

sonarqubecloud Bot commented Oct 2, 2026

Copy link
Copy Markdown

@leandrodamascena

Copy link
Copy Markdown
Contributor

Thanks for the fix, @chiruu12! I pushed a small follow-up after testing some edge cases. Normalization now raises Inexact if it would change the value, and scientific zero values like 0E+0 are preserved. I also added regression tests for these cases, including numbers inside collections and stream images.

@mergify

mergify Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@leandrodamascena
leandrodamascena merged commit 556478f into aws-powertools:develop Oct 2, 2026
15 checks passed
@boring-cyborg

boring-cyborg Bot commented Oct 2, 2026

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

@powertools-for-aws-oss-automation

Copy link
Copy Markdown

Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience!

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

Labels

commons size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: DynamoDB numbers longer than 38 characters are deserialized to the wrong value

3 participants