kafka-python icon indicating copy to clipboard operation
kafka-python copied to clipboard

KafkaConsumer.subscribe(topics='t', pattern='^t') should throw ValueError not AssertionError

Open jeffwidman opened this issue 9 years ago • 2 comments

For KafkaConsumer.subscribe() either topics or pattern must be specified but not both. While experimenting, I noticed that when I break this contract, I get an AssertionError.

Since this is caused by bad input, and not bad code, this should throw ValueError not AssertionError.

Assertions will get stripped out if python is run with the optimized flag, removing the safety net of this check. While rare in dev, some places do run python this way in production.

Happy to put together a PR if you want, but wanted to doublecheck you're on board with this change.

jeffwidman avatar Nov 29 '16 18:11 jeffwidman

makes sense and on board! I am a fan of asserts to document assumptions, but I think you're right that we're probably abusing them in cases like this.

dpkp avatar Nov 29 '16 20:11 dpkp

Also note that technically what is raised is IllegalStateError which isn't strictly an assertion. This was done to mirror the java client, which I believe raises a similar error in this case.

dpkp avatar Dec 28 '16 23:12 dpkp