Description
Currently the serializer API takes one parameter value
only. Many data ser/de library takes two parameter value
, obj
. The obj
is the current instance of the class. It allow serializer to use some "global" context information, such as value of other attribute to help with the serialization. It is very helpful in some cases such as the AWS recommended write sharding pattern https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-partition-key-sharding.html#bp-partition-key-sharding-calculated
# current API
class MyCustomAttribute(...):
def serialize(self, value):
...
# expected API
class MyCustomAttribute(...):
def serialize(self, value, obj):
...
I think it doesn't break the API if you add one parameter and also update the related method in pynamodb.models.Model
. Is it possible you can add this feature? Thank you.
I know that it causes other issue such as two attributes recursively update the value of the other fields. But most of ORM ODM frameworks such as SQLachemy, Mongoengine, attrs, marshmallow, they all takes two parameter in the serialization method. I guess maybe that is the default pattern for a ORM framework?
Thank you