Last active
January 22, 2025 07:36
-
-
Save lbenitez000/85fb43e40a7839e13405 to your computer and use it in GitHub Desktop.
A monkey patch for boto's Decimal context to allow inexact and rounded representation of floats. Used to store any float in DynamoDB when inexactitude is allowed.
This file contains hidden or 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
# Monkey patch Decimal's default Context to allow | |
# inexact and rounded representation of floats | |
import decimal | |
from boto.dynamodb.types import DYNAMODB_CONTEXT | |
# Inhibit Inexact Exceptions | |
DYNAMODB_CONTEXT.traps[decimal.Inexact] = 0 | |
# Inhibit Rounded Exceptions | |
DYNAMODB_CONTEXT.traps[decimal.Rounded] = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great solution