{"id":"3614ab5464d8d4ae","repo":"boto/boto3","slug":"value-must-be-a-nonempty-dictionary-whose-key-is-a","errorCode":null,"errorMessage":"Value must be a nonempty dictionary whose key is a valid dynamodb type.","messagePattern":"Value must be a nonempty dictionary whose key is a valid dynamodb type\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"boto3/dynamodb/types.py","lineNumber":269,"sourceCode":"\n            DynamoDB                                Python\n            --------                                ------\n            {'NULL': True}                          None\n            {'BOOL': True/False}                    True/False\n            {'N': str(value)}                       Decimal(str(value))\n            {'S': string}                           string\n            {'B': bytes}                            Binary(bytes)\n            {'NS': [str(value)]}                    set([Decimal(str(value))])\n            {'SS': [string]}                        set([string])\n            {'BS': [bytes]}                         set([bytes])\n            {'L': list}                             list\n            {'M': dict}                             dict\n\n        :returns: The pythonic value of the DynamoDB type.\n        \"\"\"\n\n        if not value:\n            raise TypeError(\n                'Value must be a nonempty dictionary whose key '\n                'is a valid dynamodb type.'\n            )\n        dynamodb_type = list(value.keys())[0]\n        try:\n            deserializer = getattr(\n                self, f'_deserialize_{dynamodb_type}'.lower()\n            )\n        except AttributeError:\n            raise TypeError(f'Dynamodb type {dynamodb_type} is not supported')\n        return deserializer(value[dynamodb_type])\n\n    def _deserialize_null(self, value):\n        return None\n\n    def _deserialize_bool(self, value):\n        return value\n","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/boto/boto3/blob/c7b4afac237b976d48395d7523eaf7cec3a450b3/boto3/dynamodb/types.py#L251-L287","documentation":"Raised by TypeDeserializer.deserialize when the input value is falsy (empty dict {}, None, empty string, 0, etc.). The deserializer expects a single-key dict like {'S': 'hello'}; an empty or falsy value has no type key to dispatch on, so the function refuses it immediately with a guard at the top of the method.","triggerScenarios":"TypeDeserializer().deserialize({}) — empty dict. Also deserialize(None), deserialize(''), or deserialize(0). Common when iterating over a response that contains missing/empty attribute values.","commonSituations":"Iterating DynamoDB Items where some attributes were not returned (None values); passing an empty dict from a malformed API response; deserializing a projection that excluded the attribute.","solutions":["Guard against falsy values before deserializing: if value: TypeDeserializer().deserialize(value).","Treat missing/empty values as None at the application layer.","Ensure the source produces proper single-key DynamoDB type dicts."],"exampleFix":"# before\nfrom boto3.dynamodb.types import TypeDeserializer\ntd = TypeDeserializer()\nfor attr, raw in item.items():\n    result[attr] = td.deserialize(raw)  # raw may be {}\n\n# after\ntd = TypeDeserializer()\nfor attr, raw in item.items():\n    result[attr] = td.deserialize(raw) if raw else None","handlingStrategy":"validation","validationCode":"from boto3.dynamodb.types import TypeDeserializer\n\ndef safe_deserialize(value):\n    if not value:\n        return None\n    return TypeDeserializer().deserialize(value)","typeGuard":"def is_valid_dynamodb_value(v) -> bool:\n    return bool(v) and isinstance(v, dict) and len(v) == 1","tryCatchPattern":null,"preventionTips":["Always falsy-check before calling deserialize().","Filter out empty/None attribute values from response dicts before deserializing.","Wrap the deserializer in a helper that returns None for empty inputs."],"tags":["dynamodb","types","deserialization","empty-value"],"analyzedSha":"c7b4afac237b976d48395d7523eaf7cec3a450b3","analyzedAt":"2026-08-04T20:35:51.598Z","schemaVersion":2}