Make error_on_callbacks a per-instance / producer config option (#2366)#3073
Make error_on_callbacks a per-instance / producer config option (#2366)#3073wgu9 wants to merge 1 commit into
Conversation
Closes dpkp#2366. Previously Future.error_on_callbacks could only be changed by overriding the class attribute, which has global effect. This makes it a per-instance option: - Future(error_on_callbacks=...) overrides a class-level default (Future._default_error_on_callbacks, still False) via a small property; None means inherit the default, so existing global overrides keep working. - KafkaProducer/RecordAccumulator/ProducerBatch thread a new 'error_on_callbacks' config (default None) down to each per-record FutureRecordMetadata, so users can enable it without global side effects. Adds unit tests for the Future option and ProducerBatch propagation.
|
This seems like an automated AI bot PR. Are you a human? What is your intention here? |
real person here. My intention was to make a genuine fix for #2366: exposing an option to enable error_on_callbacks in KafkaProducer.send. I reviewed the issue, followed the existing producer/future patterns, and ran the local producer/future tests, which passed. I did use AI assistance while preparing the PR, but I’m personally responsible for the change and happy to address review feedback myself. If this kind of AI-assisted PR is not welcome here, I’m happy to close it and I apologize for the noise. |
|
AI-assisted code is absolutely welcome (I've been using it extensively). But my question was more about "why" you chose to focus on this issue. Have you been experiencing the error_on_callbacks problem in your kafka-python application? Because I'm not actually sure whether this is an issue that needs a fix. I've left it open because I also haven't decided it doesn't need a fix. And so if you've just stumbled on the project and found an open issue and thought that with AI help you could probably write a patch then it's less helpful -- because of course I could point my AI coder at this issue for a fix just as easily. So what I'm looking for is more human insight into the why we should change this. What is the actual pain or problem you are feeling as a user of kafka-python? Can you expand on that? |
I don't have a production pain point for this one. I am a Kafka user for years and I came across the open issue and thought it looked like a clean fix, not from hitting it myself in an app. Appreciate the candid and thoughtful reply, it's a good reminder. I'll close this. |
|
Right on, well hey I totally appreciate the help. Once a new feature / arg gets merged I need to maintain it and for that I want to have strong user-empathy for what's underlying it so I know how to manage it in the future. In this case I've mostly dropped the callback/errback approach from kafka-python internals and I think probably in the next release there will be a fully async interface so that the preferred approach for catching errors would become: and in that world I think that there would no longer be a need for something like error_on_callbacks per-instance. But I'm not 100% sure and so hoping someone might provide more insight. |
Summary
Closes #2366.
Previously the only way to change
error_on_callbacks(whether exceptionsraised inside
Futurecallbacks/errbacks are re-raised vs. only logged) was tooverride the
Future.error_on_callbacksclass attribute, which has globaleffect — not viable in a large app with multiple producers that need different
behavior.
This makes it a per-instance / per-producer option while preserving the
existing global-default mechanism:
Future(error_on_callbacks=...)now stores a per-instance value. A smallread-only
error_on_callbacksproperty returns the instance value when set,otherwise the class-level default
Future._default_error_on_callbacks(still
False). PassingNone(the default) means "inherit the classdefault", so existing global overrides keep working.
KafkaProducergains anerror_on_callbacksconfig (defaultNone) that isthreaded through
RecordAccumulator→ProducerBatch→ each per-recordFutureRecordMetadata, so users can opt in without global side effects.Default behavior is unchanged.
Notes
test/__init__.pysets the testing global default via the newFuture._default_error_on_callbacks = True(wasFuture.error_on_callbacks = True),keeping "always fail during testing" intact.
for an instance/property read; no new locking.
Testing
pytest test/test_future.py test/producer/ # 315 passedNew tests:
test/test_future.py::TestFutureErrorOnCallbacks— explicit value overridesthe class default in both directions; callback/errback raising; already-done path.
test/producer/test_producer_batch.py—ProducerBatchpropagateserror_on_callbacksto record futures (default inherits, explicit overrides).