tsturzl opened a new issue #12485: URL: https://github.com/apache/pulsar/issues/12485
**Describe the bug** Python client does very bad things with values `0`, `False`, and empty strings/dicts/lists/etc. Basically any value that evaluates to False cannot be used as the value for a Field, nor can it be used as the default for the field (which has even more bizarre behavior). So anything where `not val` evaluates to `False` is not a possible value that can be used, which means zero and False essentially don't exist. The reason for this is pretty obvious, if you look at [this line](https://github.com/apache/pulsar/blob/464a9cdc21609189771f1d95ac211b69eca1454c/pulsar-client-cpp/python/pulsar/schema/definition.py#L182) it should probably just be `if val != None`, or perhaps you want certain things like an empty list to evaluate to None? Either way this seems to cause a lot of issues, and I cannot imagine this is the intended behavior because you're now expecting the user to assume any false-y value is going to be None. Booleans actually seem to work because `default()` will return `False` in stead of None, which is kind of odd since now you can never have a Boolean with the value `None`. **To Reproduce** Simply use the Python client and assign a zero value or empty string/dict/list. ``` >>> from pulsar.schema import * >>> class MyRecord(Record): ... a = Integer() ... b = Boolean() ... c = String() ... >>> r = MyRecord(a=0, b=None, c="") >>> print(r) {'_required_default': False, '_default': None, '_required': False, 'a': None, 'b': False, 'c': None} >>> print(r.a) None >>> print(r.b) # this was explicitly set to None but still comes back False instead of None False >>> print(r.c) None ``` **Expected behavior** Numeric types should be allowed to be set to `0`. Empty strings, lists, dicts, etc should also just be set as such instead of defaulted to None. The validation should not do simple `not val` evaluations on values. This is very very silly, and I cannot believe this bug has never been caught. **Screenshots** N/A **Desktop (please complete the following information):** N/A **Additional context** I'm happy to contribute a PR to fix this. In addition to these findings. -- 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]
