← Back to Pull requests

Check topic_partitions in list/alter_consumer_group_offsets() #2443

Closed
unknown closed this pull request without merging on Nov 19, 2026 10:26 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 09:03 UTC
Author

What
----
The C list_consumer_group_offsets() and alter_consumer_group_offsets() ignored the result of reading the topic_partitions attribute of the request, and of converting it with py_to_c_parts(). AdminClient validates the request first, but its checks accept list and TopicPartition subclasses, which the C methods reject. So the C methods crashed through AdminClient with such subclasses, as well as when called directly or given a request changed after that validation:

  • A missing topic_partitions came back as NULL, with the AttributeError still set. A topic_partitions that is not exactly a list, such as a list subclass, made the read fail and left the pointer NULL. Both went to py_to_c_parts(), which segfaults on NULL.

  • When an item was not exactly a TopicPartition, such as a TopicPartition subclass, py_to_c_parts() failed and returned NULL. list_consumer_group_offsets() then sent a request for all the partitions of the group and returned with the TypeError set, which Python reports as SystemError: ... returned a result with an exception set. alter_consumer_group_offsets() aborted the process on librdkafka's assertion group_id && partitions in rd_kafka_AlterConsumerGroupOffsets_new(), as it did for topic_partitions=None.

  • An error from PyObject_IsInstance() counted as a match.
  • topic_partitions is now read as a required attribute, the read and the conversion are checked, an alter request without partitions raises ValueError, as AdminClient does, and the PyObject_IsInstance() result is checked. The list and TopicPartition subclasses now raise TypeError. The group_id handling is unchanged: a failed read already ends in the ValueError for a missing group name.

    This is the same kind of problem as #2442 in alter_user_scram_credentials().

    Checklist
    ------------------

  • Contains customer facing changes? Including API/behavior changes

  • - Yes: through AdminClient, list and TopicPartition subclasses crashed the process or raised a SystemError, and now raise TypeError. CHANGELOG entry under Unreleased.
  • Did you add sufficient unit test and/or integration test coverage for this PR?

  • - New tests/test_admin_group_offsets_requests.py calls both C methods directly with a valid request and 5 invalid ones, and both AdminClient methods with a list subclass and with a TopicPartition subclass, each in a subprocess, since most of them crashed.

    References
    ----------

  • #2442 fixes the same kind of problem in alter_user_scram_credentials().
  • Test & Review
    ------------

  • CPython 3.11.16 and 3.14.7t, librdkafka 2.16.0, Linux x86_64.

  • On master, 13 of the 16 new tests fail on both; on 3.11, 6 by segfault, 4 by abort on the librdkafka assertion, and 3 with the SystemError. With this branch, all 16 pass on both, and passed 20 of 20 runs of the file on each, 3 at a time on one CPU.

  • tests/test_*.py and tests/concurrency: 653 passed and 5 skipped on 3.11. On 3.14t, 492 passed, 7 skipped and 2 failed, plus 3 collection errors, all from my environment: the 2 tests/test_unasync.py tests need isort, and tests/test_log.py, tests/test_Producer.py and tests/test_serializer_error.py need urllib3, which my 3.14t environment lacks. tests/test_kafka_error.py::test_kafkaError_unknown_error was deselected there: with that environment's pluggy it stops the whole run, which https://github.com/confluentinc/confluent-kafka-python/pull/2444 fixes.

  • tools/style-format.sh and flake8 pass on the test file. clang-format 18.1.8 and 20.1.8 report no new differences in Admin.c.

  • Merges without conflicts with master and with each of my other open pull requests, https://github.com/confluentinc/confluent-kafka-python/pull/2429 included.
  • 🤖 Generated with Claude Code

    https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

    Diff: 488 lines (+366 / -122) across 6 files Reviewer: pylaterreur Review duration: 7282m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 488 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.370
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2443"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.4% (MEDIUM) · Higher = larger blast radius
    47.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.7% · Safe to merge
    18.7%