You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by xy...@apache.org on 2022/06/22 17:22:17 UTC
[pulsar] branch master updated: [fix][python client] Fixed schema validate_type method throw a wrong exception (#16131)
This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git
The following commit(s) were added to refs/heads/master by this push:
new e9108069d9c [fix][python client] Fixed schema validate_type method throw a wrong exception (#16131)
e9108069d9c is described below
commit e9108069d9c2a0a3f14bedca0283b60a00fd659d
Author: boatrainlsz <yi...@gmail.com>
AuthorDate: Thu Jun 23 01:22:09 2022 +0800
[fix][python client] Fixed schema validate_type method throw a wrong exception (#16131)
Fixes #16056
### Motivation
The validate_type method in definition.py was intended to throw a TypeError when type of elements in array is incorrect, but the `self.array_type.python_type()` would return int type, which can not be concatenated with string. This would cause a confusing error output
### Modifications
call `self.array_type.type()` method instead of `self.array_type.python_type()`
---
pulsar-client-cpp/python/pulsar/schema/definition.py | 4 ++--
pulsar-client-cpp/python/schema_test.py | 8 ++++++++
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/pulsar-client-cpp/python/pulsar/schema/definition.py b/pulsar-client-cpp/python/pulsar/schema/definition.py
index 291909b97cd..60ab7ccbe10 100644
--- a/pulsar-client-cpp/python/pulsar/schema/definition.py
+++ b/pulsar-client-cpp/python/pulsar/schema/definition.py
@@ -444,8 +444,8 @@ class Array(Field):
for x in val:
if type(x) != self.array_type.python_type():
- raise TypeError('Array field ' + name + ' items should all be of type '
- + self.array_type.python_type())
+ raise TypeError('Array field ' + name + ' items should all be of type ' +
+ self.array_type.type())
return val
def schema(self):
diff --git a/pulsar-client-cpp/python/schema_test.py b/pulsar-client-cpp/python/schema_test.py
index 78491ba7754..47acc304ef4 100755
--- a/pulsar-client-cpp/python/schema_test.py
+++ b/pulsar-client-cpp/python/schema_test.py
@@ -1279,5 +1279,13 @@ class SchemaTest(TestCase):
self.assertTrue(b'_default' not in b)
self.assertTrue(b'_required' not in b)
self.assertTrue(b'_required_default' not in b)
+
+ def test_schema_array_wrong_type(self):
+ class SomeSchema(Record):
+ some_field = Array(Integer(), required=False, default=[])
+ # descriptive error message
+ with self.assertRaises(TypeError) as e:
+ SomeSchema(some_field=["not", "integer"])
+ self.assertEqual(str(e.exception), "Array field some_field items should all be of type int")
if __name__ == '__main__':
main()