Skip to content

Commit a4d3f90

Browse files
committed
Replaced stale pull #785; add config bool return_record_name
1 parent 8069f26 commit a4d3f90

File tree

1 file changed

+12
-3
lines changed
  • src/confluent_kafka/schema_registry

1 file changed

+12
-3
lines changed

src/confluent_kafka/schema_registry/avro.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,19 @@ class AvroDeserializer(Deserializer):
258258
from_dict (callable, optional): Callable(dict, SerializationContext) -> object.
259259
Converts dict to an instance of some object.
260260
261+
return_record_name (bool): If True, when reading a union of records, the result will
262+
be a tuple where the first value is the name of the record and the second value is
263+
the record itself. Defaults to False.
264+
261265
See Also:
262266
`Apache Avro Schema Declaration <https://avro.apache.org/docs/current/spec.html#schemas>`_
263267
264268
`Apache Avro Schema Resolution <https://avro.apache.org/docs/1.8.2/spec.html#Schema+Resolution>`_
265269
266270
"""
267-
__slots__ = ['_reader_schema', '_registry', '_from_dict', '_writer_schemas']
271+
__slots__ = ['_reader_schema', '_registry', '_from_dict', '_writer_schemas', '_return_record_name']
268272

269-
def __init__(self, schema_str, schema_registry_client, from_dict=None):
273+
def __init__(self, schema_str, schema_registry_client, from_dict=None, return_record_name=False):
270274
self._registry = schema_registry_client
271275
self._writer_schemas = {}
272276

@@ -277,6 +281,10 @@ def __init__(self, schema_str, schema_registry_client, from_dict=None):
277281
" from_dict(SerializationContext, dict) -> object")
278282
self._from_dict = from_dict
279283

284+
self._return_record_name = return_record_name
285+
if not isinstance(self._return_record_name, bool):
286+
raise ValueError("return_record_name must be a boolean value")
287+
280288
def __call__(self, value, ctx):
281289
"""
282290
Decodes a Confluent Schema Registry formatted Avro bytes to an object.
@@ -320,7 +328,8 @@ def __call__(self, value, ctx):
320328

321329
obj_dict = schemaless_reader(payload,
322330
writer_schema,
323-
self._reader_schema)
331+
self._reader_schema,
332+
self._return_record_name)
324333

325334
if self._from_dict is not None:
326335
return self._from_dict(obj_dict, ctx)

0 commit comments

Comments
 (0)