aiokafka icon indicating copy to clipboard operation
aiokafka copied to clipboard

If consumer isn't started, `getmany()` fails with `AttributeError`

Open MrCreosote opened this issue 8 months ago • 0 comments

Describe the bug If a consumer is created but not started and the genmany() method is called, an AttributeError results.

Expected behaviour A user friendly error that explains the problem should be thrown.

Environment (please complete the following information):

  • aiokafka version: 0.12.0
  • Kafka Broker version: 3.9.0
  • Other information (Confluent Cloud version, etc.): n/a

Reproducible example

async def err_on_genmany():
    kc = AIOKafkaConsumer(
        "topichere",
        bootstrap_servers=f"localhost:9092",
        auto_offset_reset="earliest"
    )
    await kc.getmany()
    kc.stop()


if __name__ == "__main__":
    asyncio.run(err_on_genmany())

Results in the output:

Traceback (most recent call last):
  File "/home/<user>test_manual/kafka_notifier_manual_test.py", line 130, in <module>
    asyncio.run(err_on_genmany())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/<user>test_manual/kafka_notifier_manual_test.py", line 121, in err_on_genmany
    await kc.getmany()
  File "/home/<user>/.local/share/virtualenvs/<dir>-2sgYN4mf/lib/python3.11/site-packages/aiokafka/consumer/consumer.py", line 1208, in getmany
    self._coordinator.check_errors()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'check_errors'

MrCreosote avatar Mar 27 '25 20:03 MrCreosote