Skip to content

Instantly share code, notes, and snippets.

@lbenitez000
Last active January 22, 2025 07:36
Show Gist options
  • Save lbenitez000/85fb43e40a7839e13405 to your computer and use it in GitHub Desktop.
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.
# 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
@manuelnaranjo
Copy link

Great solution! good catch, btw you want to fix boto3 as well

@jymoodys
Copy link

Great solution

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