Skip to content

Commit

Permalink
fix: parse topic events without struct fields (#137)
Browse files Browse the repository at this point in the history
Using to_dict on the struct includes internal fields from the protobuf struct, instead of a standard python dictionary
  • Loading branch information
jyecusch authored Apr 15, 2024
1 parent b8fa116 commit f1446ad
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion nitric/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
)
)
Expand Down
4 changes: 2 additions & 2 deletions nitric/resources/topics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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,
)
)
Expand Down

0 comments on commit f1446ad

Please sign in to comment.