@@ -350,10 +350,10 @@ async def _publish_single_topic(
350350 ) -> bool :
351351 """Publish event to a single topic.
352352
353- Constructs a full CloudEvent envelope and publishes with
354- application/cloudevents+json content type. This prevents Dapr from
355- injecting its own id/datacontenttype fields, which budnotify's
356- CloudEventBase(extra="forbid") would reject with 422 .
353+ Sends flat payload data with CloudEvent attributes passed via
354+ publish_metadata, matching the budmicroframe publish_to_topic
355+ pattern. This avoids injecting extra fields (id, datacontenttype)
356+ into the JSON body that downstream subscribers would reject .
357357
358358 Args:
359359 topic: Target topic.
@@ -370,30 +370,25 @@ async def _publish_single_topic(
370370
371371 # Copy payload to avoid mutating the shared dict across topics
372372 event_payload = payload .copy ()
373- correlation_id = event_payload .pop ("correlation_id" , None )
374-
375- # Construct a full CloudEvent envelope so Dapr does not inject
376- # its own id/datacontenttype fields (which budnotify rejects).
377- # Extension attributes (source_topic, correlation_id) go at the
378- # envelope level, not inside data.
379- cloud_event : dict [str , Any ] = {
380- "specversion" : "1.0" ,
381- "id" : str (uuid4 ()),
382- "source" : settings .name ,
383- "type" : event_type ,
384- "datacontenttype" : "application/json" ,
385- "source_topic" : topic ,
386- "data" : event_payload ,
373+ event_payload ["source" ] = settings .name
374+ event_payload ["source_topic" ] = topic
375+
376+ # Pass CloudEvent attributes via publish_metadata so Dapr
377+ # does not inject them into the JSON body.
378+ event_id = str (uuid4 ())
379+ publish_metadata = {
380+ "cloudevent.id" : event_id ,
381+ "cloudevent.source" : settings .name ,
382+ "cloudevent.type" : event_type ,
387383 }
388- if correlation_id :
389- cloud_event ["correlation_id" ] = correlation_id
390384
391385 async with DaprClient () as client :
392386 await client .publish_event (
393387 pubsub_name = self .pubsub_name ,
394388 topic_name = topic ,
395- data = json .dumps (cloud_event , cls = _DecimalEncoder ),
389+ data = json .dumps (event_payload , cls = _DecimalEncoder ),
396390 data_content_type = "application/cloudevents+json" ,
391+ publish_metadata = publish_metadata ,
397392 )
398393
399394 record_event_published (event_type )
0 commit comments