diff options
author | Samuel Taylor <github@samueltaylor.org> | 2016-11-20 14:43:26 -0600 |
---|---|---|
committer | Dana Powers <dana.powers@gmail.com> | 2016-11-20 12:43:26 -0800 |
commit | 5ad6f52a802c38b97e1fe4f6afa711ff1415d02f (patch) | |
tree | 9eec0a30efbc113b6e6a782347e40df2d158201e | |
parent | 07237d98945f8e1f1161ab5082230d9112016620 (diff) | |
download | kafka-python-5ad6f52a802c38b97e1fe4f6afa711ff1415d02f.tar.gz |
Raise exception if given a bad topic name (#824)
-rw-r--r-- | kafka/consumer/subscription_state.py | 7 |
1 files changed, 7 insertions, 0 deletions
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) |