Skip to content

schema registry protobuf serialization exception after upgrading to 2.7.0 #1904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jbouricius opened this issue Jan 16, 2025 · 7 comments
Open

Comments

@jbouricius
Copy link

Running version 2.6.1 of the library, this is approximately my code:

class FooSerializer:

    def __init__(self, topic: str, schema_registry: ConfluentSchemaRegistryClient):
        self._topic = topic
        self._protobuf_serializer = ProtobufSerializer(
            Foo,
            schema_registry,
            conf={
                "auto.register.schemas": False,
                "use.deprecated.format": False,
                "use.latest.version": True,
            },
        )

    def serialize(self, foo: Foo) -> bytearray:
        return self._protobuf_serializer(foo, SerializationContext(self._topic, MessageField.VALUE))

where Foo is some proto class already registered as the schema for the topic. This works exactly as I expect.

After upgrading to 2.7.x or 2.8.0, the same exact code hits an exception ending in this traceback:

    return self._protobuf_serializer(foo, SerializationContext(self._topic, MessageField.VALUE))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testrunner/.local/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py", line 582, in __call__
    fd_proto, pool = self._get_parsed_schema(latest_schema.schema)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testrunner/.local/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py", line 610, in _get_parsed_schema
    _resolve_named_schema(schema, self._registry, pool)
  File "/home/testrunner/.local/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py", line 207, in _resolve_named_schema
    _resolve_named_schema(referenced_schema.schema, schema_registry_client, pool, visited)
  File "/home/testrunner/.local/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py", line 208, in _resolve_named_schema
    file_descriptor_proto = _str_to_proto(ref.name, referenced_schema.schema.schema_str)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testrunner/.local/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py", line 182, in _str_to_proto
    raise SerializationError(str(e))
confluent_kafka.serialization.SerializationError: Error parsing message

I didn't see anything in the changelogs that indicated there was a breaking change here. Am I missing a change or is there some other problem? Any other information I can provide?

@franciellyferreira
Copy link

franciellyferreira commented Jan 22, 2025

Hi, I have the same problem, to temporary solve it I fixed the version 2.6.1 in the project.

@rayokota
Copy link
Member

rayokota commented Feb 7, 2025

For Protobuf, this library needs changes from confluentinc/schema-registry#3276, which will be in the next CP patch releases.

@rayokota
Copy link
Member

I believe this is fixed by #1948

@jbouricius
Copy link
Author

jbouricius commented Mar 31, 2025

I'm still seeing the error, even after upgrading to 2.9.0. The Traceback is slightly more informative:

../../../../../../../.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py:593: in __call__
    fd_proto, pool = self._get_parsed_schema(latest_schema.schema)
../../../../../../../.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py:621: in _get_parsed_schema
    _resolve_named_schema(schema, self._registry, pool)
../../../../../../../.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py:208: in _resolve_named_schema
    _resolve_named_schema(referenced_schema.schema, schema_registry_client, pool, visited)
../../../../../../../.venv/lib/python3.11/site-packages/confluent_kafka/schema_registry/protobuf.py:209: in _resolve_named_schema
    file_descriptor_proto = _str_to_proto(ref.name, referenced_schema.schema.schema_str)

and ends in

        serialized_pb = base64.standard_b64decode(schema_str.encode('ascii'))
        file_descriptor_proto = descriptor_pb2.FileDescriptorProto()
        try:
            file_descriptor_proto.ParseFromString(serialized_pb)
            file_descriptor_proto.name = name
        except DecodeError as e:
>           raise SerializationError(str(e))
E           confluent_kafka.serialization.SerializationError: Error parsing message with type 'google.protobuf.FileDescriptorProto'

@rayokota
Copy link
Member

rayokota commented Apr 1, 2025

@jbouricius , which version of CP are you using?

@jbouricius
Copy link
Author

@rayokota

Our Schema Registry is running Confluent Platform 7.5.1

@rayokota
Copy link
Member

rayokota commented Apr 2, 2025

@jbouricius , you need to use one of the latest CP releases, such as CP 7.5.8

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

No branches or pull requests

3 participants