Skip to content

Conversation

dpkp
Copy link
Owner

@dpkp dpkp commented Aug 26, 2014

Raise TypeError in kafka.producer.send_messages if any msg is not a str (or subclass)
Improve documentation
Add producer unit test

@@ -42,9 +42,14 @@ kafka = KafkaClient("localhost:9092")

# To send messages synchronously
producer = SimpleProducer(kafka)

# Note that messages must be type str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, "Note that the application is responsible for encoding messages to type str" ?

dpkp added a commit that referenced this pull request Aug 27, 2014
Strictly enforce str message type in producer.send_messages
@dpkp dpkp merged commit 695ea22 into dpkp:master Aug 27, 2014
@wizzat
Copy link
Collaborator

wizzat commented Aug 27, 2014

I remember what was going on. We had a wrapper that looked like this:

def send_messages(topic, msg_list):
    get_producer().send_messages(topic, *msg_list)

It's a super awesome abstraction to have which simplified the surrounding code a lot. However, the usage of vargs forces a lack of type safety at this level, because *msg_list simply requires an iterable. Probably not a kafka-python error.

@dpkp dpkp deleted the str_only_produce_msgs branch August 27, 2014 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants