gaoran10 opened a new issue #11473:
URL: https://github.com/apache/pulsar/issues/11473


   **Describe the bug**
   
   The Python client couldn't encode a struct schema object which has None 
fields.
   
   **To Reproduce**
   Steps to reproduce the behavior:
   
   ```
   class User(Record):
           name = String()
           age = Integer()
   
   user = User(name = 'jack', age = 18)
   data1 = schema.encode(user) // this could work well
   
   user2 = User(age = 20)
   data2 = schema.encode(user2) // encounter  error
   ```
   
   **error log**
   ```
   user:  {'_required_default': False, '_default': None, '_required': False, 
'name': 'jack', 'age': 18}
   decodeUser:  {'_required_default': False, '_default': None, '_required': 
False, 'name': 'jack', 'age': 18}
   user2:  {'_required_default': False, '_default': None, '_required': False, 
'name': None, 'age': 20}
   Traceback (most recent call last):
     File 
"/Volumes/shit/Workspaces/GitHubFork/pulsar/pulsar-client-cpp/python/schema_test.py",
 line 992, in <module>
       test.test()
     File 
"/Volumes/shit/Workspaces/GitHubFork/pulsar/pulsar-client-cpp/python/schema_test.py",
 line 985, in test
       decodeUser2 = schema.decode(data2)
     File 
"/Volumes/shit/Workspaces/GitHubFork/pulsar/pulsar-client-cpp/python/pulsar/schema/schema_avro.py",
 line 64, in decode
       return self._record_cls(**d)
     File 
"/Volumes/shit/Workspaces/GitHubFork/pulsar/pulsar-client-cpp/python/pulsar/schema/definition.py",
 line 74, in __init__
       self.__setattr__(k, kwargs[k])
     File 
"/Volumes/shit/Workspaces/GitHubFork/pulsar/pulsar-client-cpp/python/pulsar/schema/definition.py",
 line 117, in __setattr__
       value = field.validate_type(key, value)
     File 
"/Volumes/shit/Workspaces/GitHubFork/pulsar/pulsar-client-cpp/python/pulsar/schema/definition.py",
 line 290, in validate_type
       raise TypeError("Invalid type '%s' for field '%s'. Expected a string" % 
(t, name))
   TypeError: Invalid type '<class 'NoneType'>' for field 'name'. Expected a 
string
   ```
   
   **Expected behavior**
   
   Encode and decode operations should work well.
   
   


-- 
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.

To unsubscribe, e-mail: [email protected]

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


Reply via email to