Skip to content

Conversation

@ojasvajain
Copy link
Member

@ojasvajain ojasvajain commented Nov 10, 2025

Overview

  1. Fixes issue feature request: make Message type user-instantiable #1535 by allowing Message objects to be instantiable by users.
  2. Modify type hints of topic(), partition() and offset() getters to make them consistent with their implementations (ref)

Problem

Users were unable to create synthetic Message objects in their unit tests and had to resort to reading Message objects from a live Kafka cluster.

>>> import confluent_kafka
>>> confluent_kafka.Message()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create 'cimpl.Message' instances

Solution

A constructor has been defined in the Message class. All params have been intentionally kept optional to support easy instantiation without providing any params. This way of creating new messages is expected to be used only while writing unit tests. Producers and consumers will continue to use the internal factory method (Message_new0) for creating message objects.

>>> import confluent_kafka
>>> confluent_kafka.Message()
<cimpl.Message object at 0x101301640>
>>> 

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?

References

#1535

@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@ojasvajain ojasvajain self-assigned this Nov 10, 2025
@ojasvajain ojasvajain changed the title Make Message Object Instantiable Make Message Object Instantiable By Users Nov 10, 2025
@ojasvajain ojasvajain marked this pull request as ready for review November 10, 2025 08:30
@ojasvajain ojasvajain requested review from a team and MSeal as code owners November 10, 2025 08:30
Copy link
Contributor

@MSeal MSeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding tests covering various init behaviors

@sonarqube-confluent
Copy link

Quality Gate failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants