Skip to content

Fix using fastavro if reader schema is None #694

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

Closed
wants to merge 2 commits into from
Closed
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
11 changes: 8 additions & 3 deletions confluent_kafka/avro/serializer/message_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# derived from https://github.com/verisign/python-confluent-schemaregistry.git
#
import io
import json
import logging
import struct
import sys
Expand Down Expand Up @@ -79,7 +80,7 @@ def __init__(self, registry_client, reader_key_schema=None, reader_value_schema=
# Encoder support
def _get_encoder_func(self, writer_schema):
if HAS_FAST:
schema = writer_schema.to_json()
schema = json.loads(str(writer_schema))
parsed_schema = parse_schema(schema)
return lambda record, fp: schemaless_writer(fp, parsed_schema, record)
writer = avro.io.DatumWriter(writer_schema)
Expand Down Expand Up @@ -171,8 +172,12 @@ def _get_decoder_func(self, schema_id, payload, is_key=False):
if HAS_FAST:
# try to use fast avro
try:
fast_avro_writer_schema = parse_schema(writer_schema_obj.to_json())
fast_avro_reader_schema = parse_schema(reader_schema_obj.to_json())
fast_avro_writer_schema = parse_schema(json.loads(str(writer_schema_obj)))
fast_avro_reader_schema = (
parse_schema(json.loads(str(reader_schema_obj)))
if reader_schema_obj
else None
)
schemaless_reader(payload, fast_avro_writer_schema)

# If we reach this point, this means we have fastavro and it can
Expand Down