Skip to content

fix: Handled ctx=None for AvroDeserializer and ProtobufDeserializer #1974

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

Merged
merged 2 commits into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Confluent's Python client for Apache Kafka

## v2.10.1

v2.10.0 is a fix release with the following fixes

- Handled `None` value for optional `ctx` parameter in `ProtobufDeserializer` (#1939)
- Handled `None` value for optional `ctx` parameter in `AvroDeserializer` (#1973)

## v2.10.0

v2.10.0 is a feature release with the following fixes and enhancements:
Expand Down
4 changes: 2 additions & 2 deletions src/confluent_kafka/schema_registry/avro.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def __call__(self, data: bytes, ctx: Optional[SerializationContext] = None) -> U
"message was not produced with a Confluent "
"Schema Registry serializer".format(len(data)))

subject = self._subject_name_func(ctx, None)
subject = self._subject_name_func(ctx, None) if ctx else None
latest_schema = None
if subject is not None:
latest_schema = self._get_reader_schema(subject)
Expand All @@ -573,7 +573,7 @@ def __call__(self, data: bytes, ctx: Optional[SerializationContext] = None) -> U
writer_schema = self._get_parsed_schema(writer_schema_raw)

if subject is None:
subject = self._subject_name_func(ctx, writer_schema.get("name"))
subject = self._subject_name_func(ctx, writer_schema.get("name")) if ctx else None
if subject is not None:
latest_schema = self._get_reader_schema(subject)

Expand Down
13 changes: 7 additions & 6 deletions src/confluent_kafka/schema_registry/protobuf.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,15 @@ def __call__(self, message: Message, ctx: Optional[SerializationContext] = None)
raise ValueError("message must be of type {} not {}"
.format(self._msg_class, type(message)))

subject = self._subject_name_func(ctx,
message.DESCRIPTOR.full_name)
latest_schema = self._get_reader_schema(subject, fmt='serialized')
subject = self._subject_name_func(ctx, message.DESCRIPTOR.full_name) if ctx else None
latest_schema = None
if subject is not None:
latest_schema = self._get_reader_schema(subject, fmt='serialized')

if latest_schema is not None:
self._schema_id = latest_schema.schema_id
elif subject not in self._known_subjects:
references = self._resolve_dependencies(
ctx, message.DESCRIPTOR.file)
elif subject not in self._known_subjects and ctx is not None:
references = self._resolve_dependencies(ctx, message.DESCRIPTOR.file)
self._schema = Schema(
self._schema.schema_str,
self._schema.schema_type,
Expand Down