Repository: bookwyrm-social/bookwyrm

Issue:
Can't contact (remote) profiles when they don't have an avatar
**Describe the bug**
From Bookwyrm instance a, I can find @user@b (also Bookwyrm) with the search, but only when the user has an avatar set. Looking up users without an avatar results in Internal Server Error. You also do not get PMs from those users.

**To Reproduce**
Go to https://wyrms.de and look for a user w/o avi, e.g. @luxon@bookwyrm.social (direct link: https://wyrms.de/search/?q=%40luxon%40bookwyrm.social)

Proof the profile exists: https://www.bookwyrm.social/user/luxon

There was another account I tested this against, they got an avatar then and after that, the communication worked.

**Expected behavior**
Contacting other accounts should be possible whether they have an avatar or not.

**Screenshots**
If applicable, add screenshots to help explain your problem.
Screenshot 1:
![image](https://user-images.githubusercontent.com/66644064/111466095-220fd480-8723-11eb-801d-63b802f530fb.png)
Screenshot 2:
![image](https://user-images.githubusercontent.com/66644064/111466118-2d630000-8723-11eb-8564-e65c17c32c9a.png)


**Additional context**
There was a similar bug, maybe the avi ist still not sent properly. https://github.com/mouse-reeve/bookwyrm/issues/50



Discussion:

Resolving patch:
diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py
--- a/bookwyrm/activitypub/base_activity.py
+++ b/bookwyrm/activitypub/base_activity.py
@@ -75,7 +75,7 @@ def __init__(self, activity_objects=None, **kwargs):
         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)
diff --git a/bookwyrm/activitypub/person.py b/bookwyrm/activitypub/person.py
--- a/bookwyrm/activitypub/person.py
+++ b/bookwyrm/activitypub/person.py
@@ -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: {})
diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py
--- a/bookwyrm/models/fields.py
+++ b/bookwyrm/models/fields.py
@@ -73,7 +73,7 @@ def set_field_from_activity(self, instance, data):
                 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 @@ def field_to_activity(self, value):
 
     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
 


Test patch: