Description
We noticed that the id = serializers.SerializerMethodField()
that we have set on our ModelSerializer
is not being used when this package creates the json-api structure. Upon investigating I saw this line which appears to use the resource_object.pk
for the id
field:
class FooSerializer(ModelSerializer):
id = serializers.SerializerMethodField()
def get_id(self, obj):
"""
Returns the Foo.short_id as `id` for the client.
"""
return shortuuid.serialize_uuid(obj.id).decode('utf-8')
This causes a bug where if someone has written a custom serialized id
field it is bypassed completely. In our case we are customizing the id of our model for the client.
We may create a shortcut locally but I think this package should respect anything defined in the local serializers and use that rather than bypassing it. It also brings up a question on using this package in general: does this package change the way fields must be defined compared to the typical DRF way? Does it automatically translate the normal DRF serializer fields into the appropriate json-api versions? I realize it's somewhat complex so just trying to gauge how this will affect writing serializers for our project