Skip to content

Commit 60049a8

Browse files
author
Matt Howlett
authored
Merge pull request #1028 from slominskir/return_record_name
Replaced stale pull #785; add config bool return_record_name
2 parents 7f9c044 + b07cfdf commit 60049a8

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
@@ -259,15 +259,19 @@ class AvroDeserializer(Deserializer):
259259
from_dict (callable, optional): Callable(dict, SerializationContext) -> object.
260260
Converts dict to an instance of some object.
261261
262+
return_record_name (bool): If True, when reading a union of records, the result will
263+
be a tuple where the first value is the name of the record and the second value is
264+
the record itself. Defaults to False.
265+
262266
See Also:
263267
`Apache Avro Schema Declaration <https://avro.apache.org/docs/current/spec.html#schemas>`_
264268
265269
`Apache Avro Schema Resolution <https://avro.apache.org/docs/1.8.2/spec.html#Schema+Resolution>`_
266270
267271
"""
268-
__slots__ = ['_reader_schema', '_registry', '_from_dict', '_writer_schemas']
272+
__slots__ = ['_reader_schema', '_registry', '_from_dict', '_writer_schemas', '_return_record_name']
269273

270-
def __init__(self, schema_registry_client, schema_str=None, from_dict=None):
274+
def __init__(self, schema_registry_client, schema_str=None, from_dict=None, return_record_name=False):
271275
self._registry = schema_registry_client
272276
self._writer_schemas = {}
273277

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

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

322330
obj_dict = schemaless_reader(payload,
323331
writer_schema,
324-
self._reader_schema)
332+
self._reader_schema,
333+
self._return_record_name)
325334

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

0 commit comments

Comments
 (0)