giacomo-porro opened a new issue #7673:
URL: https://github.com/apache/pulsar/issues/7673


   **Describe the bug**
   When a consumer tries to consume a message that contains a boolean field 
with no default value it crashes by saying the following
   `Traceback (most recent call last):
     File "consumer.py", line 18, in <module>
       ex = msg.value()
     File 
"/Users/gporro/.virtualenvs/pulsar/lib/python2.7/site-packages/pulsar/__init__.py",
 line 177, in value
       return self._schema.decode(self._message.data())
     File 
"/Users/gporro/.virtualenvs/pulsar/lib/python2.7/site-packages/pulsar/schema/schema.py",
 line 93, in decode
       return self._record_cls(**json.loads(data))
     File 
"/Users/gporro/.virtualenvs/pulsar/lib/python2.7/site-packages/pulsar/schema/definition.py",
 line 67, in __init__
       self.__setattr__(k, kwargs[k])
     File 
"/Users/gporro/.virtualenvs/pulsar/lib/python2.7/site-packages/pulsar/schema/definition.py",
 line 98, in __setattr__
       value = field.validate_type(key, value)
     File 
"/Users/gporro/.virtualenvs/pulsar/lib/python2.7/site-packages/pulsar/schema/definition.py",
 line 137, in validate_type
       raise TypeError("Invalid type '%s' for field '%s'. Expected: %s" % 
(type(val), name, self.python_type()))
   TypeError: Invalid type '<type 'NoneType'>' for field 'c'. Expected: <type 
'bool'>`
   
   **To Reproduce**
   Steps to reproduce the behavior:
   1. Create the producer:
   `import pulsar
   from pulsar.schema import *
   
   class Example(Record):
       a = String()
       b = Integer()
       c = Boolean()
   
   client = pulsar.Client('pulsar://localhost:6650')
   producer = client.create_producer(
                       topic='tenant/namespace/my-topic',
                       schema=JsonSchema(Example) )
   
   producer.send(Example(a='Hello', b=1))`
   
   2. Create the consumer:
   `import pulsar
   from pulsar.schema import *
   
   class Example(Record):
       a = String()
       b = Integer()
       c = Boolean()
   
   
   client = pulsar.Client('pulsar://localhost:6650')
   consumer = client.subscribe(
                     topic='tenant/namespace/my-topic',
                     subscription_name='my-subscription',
                     schema=JsonSchema(Example))
   
   while True:
       msg = consumer.receive()
       ex = msg.value()
       try:
           print("Received message a={} b={} c={}".format(ex.a, ex.b, ex.c))
           # Acknowledge successful processing of the message
           consumer.acknowledge(msg)
       except:
           # Message failed to be processed
           consumer.negative_acknowledge(msg)`
   3. Run the consumer then produce the message
   
   **Expected behavior**
   Since all the fields are not required by default, I expect that the consumer 
should be able to correctly handle the message
   
   **Desktop (please complete the following information):**
    - OS: MacOS Mojave
   
   **Additional context**
   Using pulsar docker container v2.6.0, pulsar-client v2.6.0 for Python
   


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