feat(python): let poll_messages take a consumer - #3877
Open
ethanlin01x wants to merge 13 commits into
Open
Conversation
The binding had no way to name a consumer, so poll_messages could not take one. Consumer.Single and Consumer.Group encode the kind in the variant, which keeps ConsumerKind internal and rules out an invalid kind/id pair.
poll_messages built Consumer::default() internally, so every caller shared server-side consumer id 0 and silently split one offset slot. The consumer is now required, and partition_id is optional so a consumer-group poll resolves its own assignment instead of sending a partition the client may not own.
Two consumers on the same partition each receive the full set, while one consumer shared across two polls does not. A group poll with no partition reads the member's assignment.
The checked-in stub predates the current pyo3-stub-gen output, which sorts __all__ and the class definitions, so regenerating moves GlobalPermissions and UserHeaders.
ethanlin01x
force-pushed
the
feat/py-poll-messages-consumer
branch
from
August 13, 2026 16:10
c5f69bb to
f49c3c3
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3877 +/- ##
============================================
- Coverage 83.76% 82.92% -0.85%
+ Complexity 1358 1339 -19
============================================
Files 1212 1218 +6
Lines 166189 164303 -1886
Branches 133663 132607 -1056
============================================
- Hits 139210 136244 -2966
- Misses 23342 24413 +1071
- Partials 3637 3646 +9
🚀 New features to boost your workflow:
|
ethanlin01x
marked this pull request as ready for review
August 13, 2026 16:45
Contributor
Author
|
/request-review @slbotbm |
Contributor
Author
|
/ready |
slbotbm
requested changes
Aug 16, 2026
Contributor
There was a problem hiding this comment.
There are some more tests that I would like you to add:
- Create a topic with several partitions, put a distinguishable message in each partition, join one client to the group, and repeatedly call
poll_messages()without apartition_id. The client should poll all of its assigned partitions in round-robin order (assert this behaviour). - Call
poll_messages()withConsumer.Single(...)and nopartition_idafter sending messages to partition0. The call should read partition0. - Create a group member with a known assignment and call
poll_messages()with bothConsumer.Group(...)and an explicitly ownedpartition_id. The poll should return messages from that partition. - Add small tests for the Python-to-Rust conversion boundary (some of these could also be folded into existing tests):
- Omitting the required
consumerargument should raiseTypeError. - Passing a value that is not a
Consumershould raiseTypeError. - An invalid string identifier should raise
ValueError. - A negative integer or an integer larger than
u32should be rejected. - Valid numeric IDs should be accepted for both
Consumer.Single(...)andConsumer.Group(...).
- Omitting the required
- If a client polls with
Consumer.Group(group_name)without first joining that group, it has no assigned partitions and is not allowed to consume for the group. (should error)
Contributor
Author
There was a problem hiding this comment.
Addressed each point with its own commit.
Contributor
Author
There was a problem hiding this comment.
One note on the invalid string identifier: Consumer just holds a PyIdentifier, and the conversion only happens inside poll_messages. So Consumer.Single("") builds fine and you don't get ValueError: Invalid identifier until the poll, which is where the test catches it.
2 tasks
The test polls twice under one consumer and expects the second poll to be empty, which is one shared offset, not a split partition.
The existing group test uses a single partition, so it never exercises the rotation a member does over its whole assignment.
The topic carries three partitions, so the assertion also shows the fallback does not widen to the whole topic.
Asking for partitions 1 and 2 rather than 0 keeps the assertion distinct from the partition-zero fallback.
A missing or non-Consumer argument and an out-of-range numeric id are refused at the call, while a string id is validated during conversion, so the two report different exceptions.
The group is created but not joined, so the member has no assignment and the server refuses the poll.
ethanlin01x
force-pushed
the
feat/py-poll-messages-consumer
branch
from
August 16, 2026 18:16
fcb4b13 to
5e963f2
Compare
Contributor
Author
|
/ready |
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.
Which issue does this PR address?
Closes #3876
Rationale
The caller could not choose a consumer, so independent Python consumers collided on one server-side offset slot.
What changed?
poll_messagesbuiltConsumer::default()internally, which resolves to numeric id 0, so every Python process polling the same topic/partition shared one offset slot and consumer groups were unreachable.It now takes a required
Consumer(Consumer.Single(id)/Consumer.Group(id)), andpartition_idbecomes optional so a group poll can resolve the member's assignment. Breaking change: omittingconsumerraisesTypeError.Local Execution
AI Usage