Skip to content

Before the handler

 1 min Missing AMQP properties could trap Kombu in a delivery-time KeyError before user code received the message.
Published

Jul 31, 2012

I reported a Kombu consumer that could not get far enough to handle a message. Kombu normally supplied content type and encoding when it published, but a message arriving without those properties broke its librabbitmq transport during message construction.

The fix changed three dictionary reads:

delivery_tag=info.get('delivery_tag'),
content_type=props.get('content_type'),
content_encoding=props.get('content_encoding'),

They had used subscripting. A missing key raised KeyError before the user handler could inspect the message or decide what to do with it. My report described the resulting delivery loop as unrecoverable from that handler.

Using .get() let absent metadata become None in the constructed message, so the handler could receive it and decide how to proceed.

“Our publisher always sets it” was too narrow a premise for the consumer boundary. The transport could receive messages from other producers and still needed a representable state for missing properties.