Skip to content

Commit

Permalink
Check if the pk of the model is type uuid and convert it to a str closes
Browse files Browse the repository at this point in the history
  • Loading branch information
pollitux committed Sep 11, 2022
1 parent 583e843 commit c8d4d3b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion djangochannelsrestframework/observer/model_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c8d4d3b

Please sign in to comment.