From ca472716dbb2976d2ec3d54a8a898a4747ee9bf0 Mon Sep 17 00:00:00 2001 From: izzy lyseggen Date: Thu, 16 Dec 2021 16:41:09 +0000 Subject: [PATCH 1/2] feat(serialisation): allow null values --- specklepy/objects/base.py | 3 +++ specklepy/serialization/base_object_serializer.py | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/specklepy/objects/base.py b/specklepy/objects/base.py index 1f0883a..d280bee 100644 --- a/specklepy/objects/base.py +++ b/specklepy/objects/base.py @@ -252,6 +252,9 @@ class Base(_RegisteringBase): if t is None: return value + if value is None: + return None + if t.__module__ == "typing": origin = getattr(t, "__origin__") t = ( diff --git a/specklepy/serialization/base_object_serializer.py b/specklepy/serialization/base_object_serializer.py index 9ab45dd..24516a0 100644 --- a/specklepy/serialization/base_object_serializer.py +++ b/specklepy/serialization/base_object_serializer.py @@ -60,8 +60,13 @@ class BaseObjectSerializer: chunkable = False detach = False - # skip nulls or props marked to be ignored with "__" or "_" - if value is None or prop.startswith(("__", "_")): + # skip props marked to be ignored with "__" or "_" + if prop.startswith(("__", "_")): + continue + + # allow serialisation of nulls + if not value: + object_builder[prop] = value continue # don't prepopulate id as this will mess up hashing From c281a329a4e073a37e3b8c0092e70364f152257e Mon Sep 17 00:00:00 2001 From: izzy lyseggen Date: Thu, 16 Dec 2021 16:57:36 +0000 Subject: [PATCH 2/2] fix(serialisation): nulls & things ^^ --- specklepy/serialization/base_object_serializer.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/specklepy/serialization/base_object_serializer.py b/specklepy/serialization/base_object_serializer.py index 24516a0..6f639aa 100644 --- a/specklepy/serialization/base_object_serializer.py +++ b/specklepy/serialization/base_object_serializer.py @@ -64,15 +64,15 @@ class BaseObjectSerializer: if prop.startswith(("__", "_")): continue - # allow serialisation of nulls - if not value: - object_builder[prop] = value - continue - # don't prepopulate id as this will mess up hashing if prop == "id": continue + # allow serialisation of nulls + if value is None: + object_builder[prop] = value + continue + # only bother with chunking and detaching if there is a write transport if self.write_transports: dynamic_chunk_match = prop.startswith("@") and re.match(