gotopanic opened a new issue #7785:
URL: https://github.com/apache/pulsar/issues/7785


   **Describe the bug**
   The [doc 
example](http://pulsar.apache.org/docs/en/2.6.0/client-libraries-python/#complex-types)
 fails with the following error:
   
   > ValueError: 
<__main__.TestComplexSchema.test_serialize_complex_avro.<locals>.MySubRecord 
object at 0x7fabd361b7f0> (type <class 
'__main__.TestComplexSchema.test_serialize_complex_avro.<locals>.MySubRecord'>) 
do not match ['null', {'type': 'record', 'name': 'MySubRecord', 'fields': 
[{'name': 'x', 'type': ['null', 'int']}, {'name': 'y', 'type': ['null', 
'long']}, {'name': 'z', 'type': ['null', 'string']}]}]
   
   **To Reproduce**
   Run the attached test
   
   **Expected behavior**
   The complex object should be serialized and deserialized to an equivalent 
object.
   
   **Additional context**
   The offending code is in the `AvroSchema` class in 
pulsar/pulsar-client-cpp/python/pulsar/schema/schema.py:
   ```python
   class AvroSchema(Schema):
       def __init__(self, record_cls):
           super(AvroSchema, self).__init__(record_cls, _pulsar.SchemaType.AVRO,
                                            record_cls.schema(), 'AVRO')
           self._schema = record_cls.schema()
   
       def _get_serialized_value(self, x):
           if isinstance(x, enum.Enum):
               return x.name
           else:
               return x
   
       def encode(self, obj):
           self._validate_object_type(obj)
           buffer = io.BytesIO()
           m = {k: self._get_serialized_value(v) for k, v in 
obj.__dict__.items()}
           fastavro.schemaless_writer(buffer, self._schema, m)
           return buffer.getvalue()
   
       def decode(self, data):
           buffer = io.BytesIO(data)
           d = fastavro.schemaless_reader(buffer, self._schema)
           return self._record_cls(**d)
   ```
   
   Tested on 2.5.2. Code didn't change in 2.6.0.
   
[pulsar_test.txt](https://github.com/apache/pulsar/files/5047658/pulsar_test.txt)
   
   
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to