Kafka: Return consumed message results on request#69740
Open
Vamsi-klu wants to merge 2 commits into
Open
Conversation
ConsumeFromTopicOperator could not be used directly in pipelines that need values returned by its per-message processing callable.
6e5a728 to
a3efe70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ConsumeFromTopicOperatoralways returnedNone, even when its per-messageapply_functionproduced values. That made it awkward to use the operator in downstream task pipelines that expect the consumed and processed values as the task return value.closes: #56494
What Changed
This adds an opt-in
return_apply_function_resultsflag. The default behavior remains unchanged: the operator returnsNone.When the flag is enabled with per-message
apply_function, the operator collects non-Nonereturn values in consume order and returns them as a list after commits and consumer close handling.apply_function_batchbehavior is intentionally unchanged.Impact
Kafka consume tasks can now feed processed message results directly into downstream tasks when the caller opts in. Existing users are unaffected because the new behavior is disabled by default, and batch processing keeps its current return behavior.
Testing
uv run ruff format providers/apache/kafka/src/airflow/providers/apache/kafka/operators/consume.py providers/apache/kafka/tests/unit/apache/kafka/operators/test_consume.pyuv run ruff check --fix providers/apache/kafka/src/airflow/providers/apache/kafka/operators/consume.py providers/apache/kafka/tests/unit/apache/kafka/operators/test_consume.pyUV_CACHE_DIR=/tmp/uv-cache uv run --project providers/apache/kafka pytest providers/apache/kafka/tests/unit/apache/kafka/operators/test_consume.py -xvsgit diff --checkThe tests cover the problem statement expectations: default
Nonereturn, opt-in result collection, filteringNone, preserving consume order across batches, and leavingapply_function_batchreturn behavior unchanged.Was generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-5) following the guidelines