Merge pull request #756 from mouse-reeve/user-error

Fixes failed serialization of empty avatar field
This commit is contained in:
Mouse Reeve 2021-03-17 14:47:16 -07:00 committed by GitHub
commit 284366e46f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

View file

@ -75,7 +75,7 @@ class ActivityObject:
for field in fields(self):
try:
value = kwargs[field.name]
if value in (None, MISSING):
if value in (None, MISSING, {}):
raise KeyError()
try:
is_subclass = issubclass(field.type, ActivityObject)

View file

@ -24,7 +24,7 @@ class Person(ActivityObject):
outbox: str
followers: str
publicKey: PublicKey
endpoints: Dict
endpoints: Dict = None
name: str = None
summary: str = None
icon: Image = field(default_factory=lambda: {})

View file

@ -73,7 +73,7 @@ class ActivitypubFieldMixin:
raise
value = getattr(data, "actor")
formatted = self.field_from_activity(value)
if formatted is None or formatted is MISSING:
if formatted is None or formatted is MISSING or formatted == {}:
return
setattr(instance, self.name, formatted)
@ -101,7 +101,7 @@ class ActivitypubFieldMixin:
def field_from_activity(self, value):
""" formatter to convert activitypub into a model value """
if hasattr(self, "activitypub_wrapper"):
if value and hasattr(self, "activitypub_wrapper"):
value = value.get(self.activitypub_wrapper)
return value