Skip to content

Commit

Permalink
Check for zero-length assignment (#83)
Browse files Browse the repository at this point in the history
* Check for zero-length assignment

* Bump version of flake8 to avoid a dependency error with pyflakes

* Fix minor flake8 warnings
  • Loading branch information
toddpalino committed Jan 7, 2018
1 parent 8b41531 commit 79639e5
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion kafka/tools/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def clear_members(self):
def add_member(self, name, client_id=None, client_host=None, metadata=None, assignment=None):
new_member = GroupMember(name, client_id, client_host, metadata, assignment)
new_member.group = self
if (self.protocol_type == 'consumer') and (assignment is not None):
if (self.protocol_type == 'consumer') and (assignment is not None) and (len(assignment) > 0):
new_member.set_assignment()
self.members.append(new_member)

Expand Down
2 changes: 1 addition & 1 deletion kafka/tools/protocol/requests/join_group_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _parse_group_protocol(protocol):
else:
try:
return {'protocol_name': pparts[0], 'protocol_metadata': binascii.unhexlify(pparts[1])}
except:
except (binascii.Error, TypeError):
raise ArgumentError("group_protocol_metadata must be empty or a hex string")


Expand Down
2 changes: 1 addition & 1 deletion kafka/tools/protocol/requests/sync_group_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def process_arguments(cls, cmd_args):

try:
member_assignments = binascii.unhexlify(cmd_args[3])
except:
except (binascii.Error, TypeError):
raise ArgumentError("member_assignments must be a hex string")

try:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def run(self):
],
setup_requires=[
'pytest-runner',
'flake8==3.4.1',
'flake8',
],
extras_require={
'dev': ['check-manifest'],
Expand Down
6 changes: 3 additions & 3 deletions tests/tools/models/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ def test_cluster_max_replication_factor(self):

def test_cluster_log_info(self):
self.add_brokers(2)
with LogCapture() as l:
with LogCapture() as line:
self.cluster.log_broker_summary()
l.check(('kafka-tools', 'INFO', 'Broker 1: partitions=0/0 (0.00%), size=0'),
('kafka-tools', 'INFO', 'Broker 2: partitions=0/0 (0.00%), size=0'))
line.check(('kafka-tools', 'INFO', 'Broker 1: partitions=0/0 (0.00%), size=0'),
('kafka-tools', 'INFO', 'Broker 2: partitions=0/0 (0.00%), size=0'))

def test_cluster_output_json(self):
self.add_topics(2)
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ basepython =
deps =
check-manifest
{py27,py34,py35}: readme_renderer
flake8
flake8>=3.5.0
codeclimate-test-reporter
coverage
setuptools>30
Expand Down

0 comments on commit 79639e5

Please sign in to comment.