forked from mirrors/bookwyrm
Fixes bug in serializing dataclasses in place
This commit is contained in:
parent
cbf5479253
commit
8bb20730fc
1 changed files with 4 additions and 5 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue