diff --git a/djangochannelsrestframework/observer/model_observer.py b/djangochannelsrestframework/observer/model_observer.py index d9bd7c5..56b3f32 100644 --- a/djangochannelsrestframework/observer/model_observer.py +++ b/djangochannelsrestframework/observer/model_observer.py @@ -4,7 +4,7 @@ from enum import Enum from functools import partial from typing import Type, Dict, Any, Set, Optional -from uuid import uuid4 +from uuid import uuid4, UUID from asgiref.sync import async_to_sync from channels.layers import get_channel_layer @@ -182,6 +182,10 @@ def serialize(self, instance, action, **kwargs) -> Dict[str, Any]: else: message_body["pk"] = instance.pk + # Check if the pk of the model is UUID type and convert it to a string + if isinstance(message_body['pk'], UUID): + message_body.update({'pk': str(message_body['pk'])}) + message = dict( type=self.func.__name__.replace("_", "."), body=message_body,