Fixes bug in serializing dataclasses in place

This commit is contained in:
Mouse Reeve 2021-02-17 09:33:33 -08:00
parent cbf5479253
commit 8bb20730fc

View file

@ -162,15 +162,14 @@ class ActivityObject:
def serialize(self): def serialize(self):
''' convert to dictionary with context attr ''' ''' convert to dictionary with context attr '''
data = self.__dict__ data = self.__dict__.copy()
# recursively serialize # recursively serialize
for (k, v) in data.items(): for (k, v) in data.items():
try: try:
is_subclass = issubclass(type(v), ActivityObject) if issubclass(type(v), ActivityObject):
data[k] = v.serialize()
except TypeError: except TypeError:
is_subclass = False pass
if is_subclass:
data[k] = v.serialize()
data = {k:v for (k, v) in data.items() if v is not None} data = {k:v for (k, v) in data.items() if v is not None}
data['@context'] = 'https://www.w3.org/ns/activitystreams' data['@context'] = 'https://www.w3.org/ns/activitystreams'
return data return data