diff options
author | Bernd Wechner <bernd.wechner@gmail.com> | 2020-04-23 10:21:06 +1000 |
---|---|---|
committer | Asif Saif Uddin <auvipy@gmail.com> | 2020-04-24 10:38:47 +0600 |
commit | 93242848b8eda6532f2928e7058fff5fe3023115 (patch) | |
tree | 4d7df45de328e4b30c217b78868bb9cd4a4dab57 | |
parent | 4dadaad6e736cc0ca1974aba68d07053b0e6ccea (diff) | |
download | kombu-93242848b8eda6532f2928e7058fff5fe3023115.tar.gz |
Another possible fix for #1174
Flake8 compliant this time.
Unit test to follow if possible but see no unit testing infrastructure in the repo. Fail behaviour on this is Exchange.publish(text) crashes with an encoding error. A Pass is that the message is published, which can be confirmed with Queue.get() and comparing the payload with that which was published. Requires a running RabbitMQ instance to test (as that is the context of the crash).
A unit test though, while holding value is of the functionality of Exchange.publish() - currently broken for text messages, is not central to the value of fixing this break.
ref: https://github.com/celery/kombu/issues/1174
-rw-r--r-- | kombu/entity.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/kombu/entity.py b/kombu/entity.py index deac788b..36976218 100644 --- a/kombu/entity.py +++ b/kombu/entity.py @@ -245,9 +245,11 @@ class Exchange(MaybeChannelBound): headers (Dict): Message headers. """ - # XXX This method is unused by kombu itself AFAICT [ask]. properties = {} if properties is None else properties properties['delivery_mode'] = maybe_delivery_mode(self.delivery_mode) + if (isinstance(body, string_t) and + properties.get('content_encoding', None)) is None: + kwargs['content_encoding'] = 'utf-8' return self.channel.prepare_message( body, properties=properties, |