From c8d4d3b74f455267edefd81d3af8e19886bcd47f Mon Sep 17 00:00:00 2001 From: pollitux Date: Sun, 11 Sep 2022 09:13:27 -0500 Subject: [PATCH] Check if the pk of the model is type uuid and convert it to a str closes #154 --- djangochannelsrestframework/observer/model_observer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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,