You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/07/27 10:25:30 UTC
[GitHub] [pulsar] giacomo-porro opened a new issue #7673: Consumer error on schema boolean field validation - Python client
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:
users@infra.apache.org
[GitHub] [pulsar] codelipenghui closed issue #7673: Consumer error on schema boolean field validation - Python client
Posted by GitBox <gi...@apache.org>.
codelipenghui closed issue #7673:
URL: https://github.com/apache/pulsar/issues/7673
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [pulsar] zymap commented on issue #7673: Consumer error on schema boolean field validation - Python client
Posted by GitBox <gi...@apache.org>.
zymap commented on issue #7673:
URL: https://github.com/apache/pulsar/issues/7673#issuecomment-698073655
@hangc0276 will handle this issue.
----------------------------------------------------------------
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:
users@infra.apache.org
[GitHub] [pulsar] zymap commented on issue #7673: Consumer error on schema boolean field validation - Python client
Posted by GitBox <gi...@apache.org>.
zymap commented on issue #7673:
URL: https://github.com/apache/pulsar/issues/7673#issuecomment-697290902
Maybe we can given a default vault when there no values for the struct messages.
----------------------------------------------------------------
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:
users@infra.apache.org