Skip to content

Commit f4fba14

Browse files
fatihozer0nevzatseferogludependabot[bot]mdumandagmeltemtokgoz
authored
Fix custom lookup serializer for class error [API-1669] (#603)
* fix custom lookup serializer for class error * change __subclasses__ to __mro__ * add test for custom global serialization * Add put_all() to MultiMap [API-1235] (#600) Added multimap put-all * Bump hazelcast in /examples/paging-predicate/member-with-comparator (#602) Bumps [hazelcast](https://github.com/hazelcast/hazelcast) from 5.1 to 5.1.3. - [Release notes](https://github.com/hazelcast/hazelcast/releases) - [Commits](hazelcast/hazelcast@v5.1...v5.1.3) --- updated-dependencies: - dependency-name: com.hazelcast:hazelcast dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Convert `Config` classes to public API [API-1280] (#521) * Convert `Config` classes to public API These were converted into private classes during the 4.0 migration, as we were only supporting keyword arguments for the client configuration. However, that led to a poor user experience, as we had to use `**kwargs`, instead of listing all the configuration elements in the client constructor. (IDEs become painfully slow once we list all keyword arguments, as there are too many of them) The solution to this problem is to make the Config classes public API and make the client able to use it directly. ```python config = Config() config.cluster_name = "dev2" client = HazelcastClient(config) ``` We provide full type hints for config elements. * bump the client version used in tests * address review comments * shutdown clients in teardown method * Add code sample to show how Hazelcast works with Pandas DataFrames. (#604) Added code sample to show how Hazelcast works with Pandas DataFrames. * fix the problems of added test * test after updating branch * test after updating branch * test after updating branch * add another test * fix some typos and unnecessary parts * fix the test * fix the test * Update custom_global_serialization_test.py --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Nevzat Seferoglu <nevzatseferoglu@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Metin Dumandag <metin@hazelcast.com> Co-authored-by: Meltem Tokgöz <meltemtgz@gmail.com> Co-authored-by: Metin Dumandag <29387993+mdumandag@users.noreply.github.com>
1 parent d99164b commit f4fba14

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

hazelcast/serialization/service.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ def lookup_custom_serializer(self, obj_type):
450450
serializer = self._type_dict.get(obj_type, None)
451451
if serializer is not None:
452452
return serializer
453-
for super_type in obj_type.__subclasses__():
453+
454+
for super_type in obj_type.__mro__:
454455
serializer = self.register_from_super_type(obj_type, super_type)
455456
if serializer is not None:
456457
return serializer

tests/unit/serialization/custom_global_serialization_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __eq__(self, other):
4242
return False
4343

4444

45+
class ChildCustomClass(CustomClass):
46+
pass
47+
48+
4549
class CustomSerializer(StreamSerializer):
4650
def write(self, out, obj):
4751
if isinstance(obj, CustomClass):
@@ -128,3 +132,25 @@ def test_double_register_custom_serializer(self):
128132

129133
with self.assertRaises(ValueError):
130134
service._registry.safe_register_serializer(TheOtherCustomSerializer, CustomClass)
135+
136+
def test_serializing_class_instances(self):
137+
config = Config()
138+
config.custom_serializers = {CustomClass: CustomSerializer}
139+
service = SerializationServiceV1(config)
140+
141+
for clazz in (CustomClass, ChildCustomClass):
142+
data = service.to_data(clazz)
143+
deserialized = service.to_object(data)
144+
self.assertEqual(clazz, deserialized)
145+
146+
def test_serializing_child_class_instances_with_super_class_serializer(self):
147+
config = Config()
148+
config.custom_serializers = {CustomClass: CustomSerializer}
149+
service = SerializationServiceV1(config)
150+
151+
obj = ChildCustomClass("uid", "some name", "description text", "CUSTOM")
152+
data = service.to_data(obj)
153+
deserialized = service.to_object(data)
154+
155+
self.assertIsInstance(deserialized, CustomClass)
156+
self.assertEqual(obj, deserialized)

0 commit comments

Comments
 (0)