Ingestion: Kafka protobuf schema parsing only works if payload type is named the same as the topic
Affected module Ingestion
Describe the bug
When ingesting from Kafka, schema parsing fails unless the payload type name is similar to the topic name. For example, in a topic named address_book the payload module must be named AddressBook. Otherwise the parsing fails with a warning similar to this:
[2024-02-20T16:10:40.346+0000] {common_broker_source.py:104} INFO - Fetching topic config loans
[2024-02-20T16:10:40.497+0000] {protobuf_parser.py:165} WARNING - Unable to create protobuf python module for loans: module 'loans_pb2' has no attribute 'Loans'
[2024-02-20T16:10:40.499+0000] {protobuf_parser.py:200} WARNING - Unable to parse protobuf schema for loans: 'NoneType' object has no attribute 'DESCRIPTOR'
In the OMD UI the result is that only the text version of the schema appears. No fields are displayed and there's no way to add tags or glossary terms to the schema:
To Reproduce
- In Kafka, create a topic.
- Using schema registry, create a Protobuf schema for the topic but give the top-level message a name other than the topic name.
- Run an ingestion against the Kafka cluster.
- In the UI the topic will only have the Protobuf schema in text format.
Expected behavior The full schema with fields, tags, and glossary terms should be displayed for the topic.
Version:
- OS: Linux
- Python version: 3.10.13
- OpenMetadata version: 1.3.0
- OpenMetadata Ingestion package version: `openmetadata-ingestion[docker]==1.3.0.1
Additional context N/A
@ulixius9 @OnkarVO7 we might run into this issue quickly. Lets target for 1.6.0
hey, any progress on this issue?
@harshach , @ulixius9 hello sir
i have investigated this issue and was able to reproduce it locally when the protobuf message name differs from the Kafka topic name.
root cause:
the current implementation derives the message class from the topic name using PascalCase (e.g. loans --> Loans). This fails when the actual Protobuf message name does not follow that convention, resulting in:
module '<topic>_pb2' has no attribute '<TopicName>' and subsequent NoneType.DESCRIPTOR errors.
proposed solution (implemented & tested):
- retain existing PascalCase lookup for backward compatibility
- add a fallback using
pb2_module.DESCRIPTOR.message_types_by_nameto dynamically discover available top-level messages - if multiple messages exist, select the first one (with logging for visibility)
this approach avoids breaking existing behavior while making parsing robust to naming differences
Changes included:
- Refactored message resolution into a helper method
- Added descriptor-based fallback logic
- Improved logging when fallback is triggered
- Added unit tests covering:
- message name != topic name (core issue)
- legacy behavior (matching names)
- edge cases (no descriptor / multiple messages)
all tests are passing locally
happy to open a PR please let me know if I can take this up or if any changes are preferred before I submit
Thanks!