Skip to content

Commit

Permalink
🎨 update to use new pydantic helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ff137 committed Sep 19, 2023
1 parent 48561f5 commit ea48ab2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions fastapi_websocket_pubsub/event_broadcaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .event_notifier import ALL_TOPICS, EventNotifier, Subscription, TopicList
from .logger import get_logger
from .util import get_model_serializer
from .util import pydantic_serialize

logger = get_logger("EventBroadcaster")

Expand Down Expand Up @@ -181,9 +181,8 @@ async def __broadcast_notifications__(self, subscription: Subscription, data):
async with self._broadcast_type(
self._broadcast_url
) as sharing_broadcast_channel:
model_serializer = get_model_serializer()
await sharing_broadcast_channel.publish(
self._channel, model_serializer(note)
self._channel, pydantic_serialize(note)
)

async def _subscribe_to_all_topics(self):
Expand Down
5 changes: 2 additions & 3 deletions fastapi_websocket_pubsub/event_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pydantic import BaseModel # pylint: disable=no-name-in-module

from .logger import get_logger
from .util import get_model_dict
from .util import pydantic_to_dict

logger = get_logger("EventNotifier")

Expand Down Expand Up @@ -130,8 +130,7 @@ async def subscribe(
)
subscriptions.append(new_subscription)
new_subscriptions.append(new_subscription)
model_dict = get_model_dict()
logger.debug(f"New subscription {model_dict(new_subscription)}")
logger.debug(f"New subscription {pydantic_to_dict(new_subscription)}")
await EventNotifier.trigger_events(
self._on_subscribe_events, subscriber_id, topics
)
Expand Down
7 changes: 4 additions & 3 deletions fastapi_websocket_pubsub/rpc_event_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .event_notifier import EventNotifier, Subscription, TopicList
from .logger import get_logger
from .util import get_model_dict
from .util import pydantic_to_dict


class RpcEventServerMethods(RpcMethodsBase):
Expand All @@ -25,8 +25,9 @@ async def subscribe(self, topics: TopicList = []) -> bool:
async def callback(subscription: Subscription, data):
# remove the actual function
sub = subscription.copy(exclude={"callback"})
model_dict = get_model_dict()
self.logger.info(f"Notifying other side: subscription={model_dict(subscription, exclude={'callback'})}, data={data}, channel_id={self.channel.id}")
self.logger.info(
f"Notifying other side: subscription={pydantic_to_dict(subscription, exclude={'callback'})}, data={data}, channel_id={self.channel.id}"
)
await self.channel.other.notify(subscription=sub, data=data)

if self._rpc_channel_get_remote_id:
Expand Down

0 comments on commit ea48ab2

Please sign in to comment.