Skip to content

Custom attribute with both NUMBER and BOOL values #1214

Open
@Shogo1222

Description

@Shogo1222

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))

if self.attr_type not in value:

I see here that it may not be supported, but if there is another way, please let me know.

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions