Open
Description
Hi,
How can I create a custom attribute that contains both number and BOOL values?
NUMBER may have been mixed up with past data in the same attribute in DynamoDB.
I would like to read all the numbers and BOOL values in DynamoDB and convert them to BOOL.
However, the attr_type
must be specified, and it can only be either BOOL or number.
I would appreciate it if you could tell me how to resolve this issue.
DynamoDB:
{'value': {'N': '0'}}
{'value': {'BOOL': '0'}}
CustomAttribute:
class CustomAttribute(Attribute):
def serialize(self, value):
if value is None:
return None
elif value:
return True
else:
return False
def deserialize(self, value):
if value is None:
return None
elif isinstance(value, bool):
return bool(value)
elif isinstance(value, str):
return bool(json.loads(value))
PynamoDB/pynamodb/attributes.py
Line 194 in e8d3bb4
I see here that it may not be supported, but if there is another way, please let me know.
Thanks.
Metadata
Metadata
Assignees
Labels
No labels