diff --git a/nitric/context.py b/nitric/context.py index 7e5f382..e696998 100644 --- a/nitric/context.py +++ b/nitric/context.py @@ -31,6 +31,7 @@ from nitric.proto.topics.v1 import ClientMessage as TopicClientMessage from nitric.proto.topics.v1 import MessageResponse as TopicResponse from nitric.proto.topics.v1 import ServerMessage as TopicServerMessage +from nitric.utils import dict_from_struct Record = Dict[str, Union[str, List[str]]] PROPAGATOR = propagate.get_global_textmap() @@ -173,7 +174,7 @@ def _from_request(msg: TopicServerMessage) -> MessageContext: """Construct a new EventContext from a Topic trigger from the Nitric Membrane.""" return MessageContext( request=MessageRequest( - data=msg.message_request.message.struct_payload.to_dict(), + data=dict_from_struct(msg.message_request.message.struct_payload), topic=msg.message_request.topic_name, ) ) diff --git a/nitric/resources/topics.py b/nitric/resources/topics.py index 811ee7d..c430244 100644 --- a/nitric/resources/topics.py +++ b/nitric/resources/topics.py @@ -37,7 +37,7 @@ from nitric.proto.topics.v1 import RegistrationRequest, SubscriberStub from nitric.proto.topics.v1 import TopicPublishRequest, TopicsStub from nitric.resources.resource import SecureResource -from nitric.utils import new_default_channel, struct_from_dict +from nitric.utils import dict_from_struct, new_default_channel, struct_from_dict TopicPermission = Literal["publish"] @@ -131,7 +131,7 @@ def decorator(func: EventHandler) -> None: def _message_context_from_proto(msg: ProtoMessageRequest) -> MessageContext: return MessageContext( request=MessageRequest( - data=msg.message.struct_payload.to_dict(), + data=dict_from_struct(msg.message.struct_payload), topic=msg.topic_name, ) )