PynamoDB icon indicating copy to clipboard operation
PynamoDB copied to clipboard

deserialize is not called for null values

Open Ted-Barrett opened this issue 5 months ago • 1 comments

I would like to handle null values when deserializing. I have the following custom attribute:

class TestAttribute(Attribute):
    attr_type = BINARY

    def serialize(self, value: Any) -> Any:
        return json.dumps(value)
    def deserialize(self, value: Any) -> Any:
        raise RuntimeError("STOP!!")

being used in a model:

class MyModel(Model):
    test_field = TestAttribute(null=True)

If the field has data in it, I get the runtime error STOP!! as expected.

If the field is empty, there is no such error, and e.test_field is None.

How can I handle the behaviour when a value is null?

Ted-Barrett avatar Sep 08 '24 05:09 Ted-Barrett