From 5ad6f52a802c38b97e1fe4f6afa711ff1415d02f Mon Sep 17 00:00:00 2001 From: Samuel Taylor Date: Sun, 20 Nov 2016 14:43:26 -0600 Subject: Raise exception if given a bad topic name (#824) --- kafka/consumer/subscription_state.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'kafka/consumer') diff --git a/kafka/consumer/subscription_state.py b/kafka/consumer/subscription_state.py index fac1a98..4366010 100644 --- a/kafka/consumer/subscription_state.py +++ b/kafka/consumer/subscription_state.py @@ -128,15 +128,22 @@ class SubscriptionState(object): Raises: IllegalStateErrror: if assign_from_user has been used already + TypeError: if a non-str topic is given """ if self._user_assignment: raise IllegalStateError(self._SUBSCRIPTION_EXCEPTION_MESSAGE) + if isinstance(topics, str): + topics = [topics] + if self.subscription == set(topics): log.warning("subscription unchanged by change_subscription(%s)", topics) return + if any(not isinstance(t, str) for t in topics): + raise TypeError('All topics must be strings') + log.info('Updating subscribed topics to: %s', topics) self.subscription = set(topics) self._group_subscription.update(topics) -- cgit v1.2.1