{"record":{"id":"a235c6851b5442ae","repo":"boto/boto3","slug":"float-types-are-not-supported-use-decimal-types-i","errorCode":null,"errorMessage":"Float types are not supported. Use Decimal types instead.","messagePattern":"Float types are not supported\\. Use Decimal types instead\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"boto3/dynamodb/types.py","lineNumber":171,"sourceCode":"            raise TypeError(msg)\n\n        return dynamodb_type\n\n    def _is_null(self, value):\n        if value is None:\n            return True\n        return False\n\n    def _is_boolean(self, value):\n        if isinstance(value, bool):\n            return True\n        return False\n\n    def _is_number(self, value):\n        if isinstance(value, (int, Decimal)):\n            return True\n        elif isinstance(value, float):\n            raise TypeError(\n                'Float types are not supported. Use Decimal types instead.'\n            )\n        return False\n\n    def _is_string(self, value):\n        if isinstance(value, str):\n            return True\n        return False\n\n    def _is_binary(self, value):\n        if isinstance(value, (Binary, bytearray, bytes)):\n            return True\n        return False\n\n    def _is_set(self, value):\n        if isinstance(value, collections_abc.Set):\n            return True\n        return False","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/boto/boto3/blob/6e10b029c1326a437932a8b24f38af69fd986e15/boto3/dynamodb/types.py#L153-L189","documentation":"DynamoDB stores numbers as arbitrary-precision decimals; IEEE-754 floats lose precision and cannot round-trip. TypeSerializer._is_number accepts int and Decimal but raises TypeError('Float types are not supported. Use Decimal types instead.') when given a Python float, to prevent silent precision loss.","triggerScenarios":"Putting {'price': 19.99} or any item attribute that is a Python float; computing a value with / or math.* and storing the float result directly.","commonSituations":"JSON parsing with default json.load yields floats; arithmetic producing floats; pandas/numpy float64 values; migrating from a system that allowed floats.","solutions":["Wrap numeric values with Decimal(str(value)) before storing: Decimal(str(19.99)).","Parse JSON with parse_float=Decimal.","Configure boto3 with DYNAMODB_CONTEXT traps if you need stricter handling."],"exampleFix":"# before\nfrom decimal import Decimal\ntable.put_item(Item={'price': 19.99})\n# after\nfrom decimal import Decimal\ntable.put_item(Item={'price': Decimal('19.99')})\n# or json -> Decimal\nimport json\nobj = json.loads(text, parse_float=Decimal)","handlingStrategy":"validation","validationCode":"from decimal import Decimal\ndef to_decimal(v):\n    if isinstance(v, float):\n        return Decimal(str(v))\n    if isinstance(v, (int, Decimal)):\n        return Decimal(v)\n    raise TypeError(f'cannot convert {type(v)} to Decimal')\nitem = {k: to_decimal(v) for k, v in item.items() if isinstance(v, (int, float, Decimal))}","typeGuard":"from decimal import Decimal\ndef is_dynamo_number(v) -> bool:\n    return isinstance(v, (int, Decimal)) and not isinstance(v, bool)","tryCatchPattern":"try:\n    table.put_item(Item=item)\nexcept TypeError as e:\n    if 'Float types' in str(e):\n        item = {k: (Decimal(str(v)) if isinstance(v, float) else v) for k, v in item.items()}\n        table.put_item(Item=item)\n    else:\n        raise","preventionTips":["Parse JSON with parse_float=Decimal.","Wrap computed numerics in Decimal(str(...)).","Lint for float literals in put_item Item dicts."],"tags":["dynamodb","types","number","decimal","boto3"],"backgroundTag":null,"analyzedSha":"6e10b029c1326a437932a8b24f38af69fd986e15","analyzedAt":"2026-08-11T20:52:47.213Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}