Skip to content

Commit f1446ad

Browse files
authored
fix: parse topic events without struct fields (#137)
Using to_dict on the struct includes internal fields from the protobuf struct, instead of a standard python dictionary
1 parent b8fa116 commit f1446ad

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

nitric/context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from nitric.proto.topics.v1 import ClientMessage as TopicClientMessage
3232
from nitric.proto.topics.v1 import MessageResponse as TopicResponse
3333
from nitric.proto.topics.v1 import ServerMessage as TopicServerMessage
34+
from nitric.utils import dict_from_struct
3435

3536
Record = Dict[str, Union[str, List[str]]]
3637
PROPAGATOR = propagate.get_global_textmap()
@@ -173,7 +174,7 @@ def _from_request(msg: TopicServerMessage) -> MessageContext:
173174
"""Construct a new EventContext from a Topic trigger from the Nitric Membrane."""
174175
return MessageContext(
175176
request=MessageRequest(
176-
data=msg.message_request.message.struct_payload.to_dict(),
177+
data=dict_from_struct(msg.message_request.message.struct_payload),
177178
topic=msg.message_request.topic_name,
178179
)
179180
)

nitric/resources/topics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from nitric.proto.topics.v1 import RegistrationRequest, SubscriberStub
3838
from nitric.proto.topics.v1 import TopicPublishRequest, TopicsStub
3939
from nitric.resources.resource import SecureResource
40-
from nitric.utils import new_default_channel, struct_from_dict
40+
from nitric.utils import dict_from_struct, new_default_channel, struct_from_dict
4141

4242
TopicPermission = Literal["publish"]
4343

@@ -131,7 +131,7 @@ def decorator(func: EventHandler) -> None:
131131
def _message_context_from_proto(msg: ProtoMessageRequest) -> MessageContext:
132132
return MessageContext(
133133
request=MessageRequest(
134-
data=msg.message.struct_payload.to_dict(),
134+
data=dict_from_struct(msg.message.struct_payload),
135135
topic=msg.topic_name,
136136
)
137137
)

0 commit comments

Comments
 (0)