jeames00 commented on issue #7695:
URL: https://github.com/apache/pulsar/issues/7695#issuecomment-734016251
I managed to override the schema classmethod correctly (I think):
```
import pulsar
from pulsar.schema import *
class Example(Record):
@classmethod
def schema(cls):
schema = super().schema()
for i, field_default in
enumerate([cls._fields[field['name']].default() for field in schema['fields']]):
schema['fields'][i]['default'] = field_default
return schema
a = String()
b = Integer()
c = Boolean()
d = String()
client = pulsar.Client('pulsar://localhost:6650')
producer = client.create_producer(
topic='my-topic3',
schema=AvroSchema(Example) )
for i in range(10):
producer.send(Example(a='Hello!', b=1, c=True, d='new field'))
client.close()
```
However it doesn't seem to work with 'AvroSchema', after inserting a new
field and running again I receive the error:
```
Traceback (most recent call last):
File "producer.py", line 28, in <module>
schema=AvroSchema(Example) )
File
"/home/joel/miniconda3/envs/pulsar/lib/python3.7/site-packages/pulsar/__init__.py",
line 531, in create_producer
p._producer = self._client.create_producer(topic, conf)
Exception: Pulsar error: UnknownError
```
----------------------------------------------------------------
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]