Skip to content

Commit 5ad6f52

Browse files
ssaammdpkp
authored andcommitted
Raise exception if given a bad topic name (dpkp#824)
1 parent 07237d9 commit 5ad6f52

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

kafka/consumer/subscription_state.py

+7
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,22 @@ def change_subscription(self, topics):
128128
129129
Raises:
130130
IllegalStateErrror: if assign_from_user has been used already
131+
TypeError: if a non-str topic is given
131132
"""
132133
if self._user_assignment:
133134
raise IllegalStateError(self._SUBSCRIPTION_EXCEPTION_MESSAGE)
134135

136+
if isinstance(topics, str):
137+
topics = [topics]
138+
135139
if self.subscription == set(topics):
136140
log.warning("subscription unchanged by change_subscription(%s)",
137141
topics)
138142
return
139143

144+
if any(not isinstance(t, str) for t in topics):
145+
raise TypeError('All topics must be strings')
146+
140147
log.info('Updating subscribed topics to: %s', topics)
141148
self.subscription = set(topics)
142149
self._group_subscription.update(topics)

0 commit comments

Comments
 (0)