From e58ef83f20c17a62859a81228531e1564d5f4134 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 12 Dec 2020 15:44:17 -0800 Subject: [PATCH] Fixes image fields breaking user import --- bookwyrm/activitypub/base_activity.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index b77e9e77e..ed19af992 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -81,6 +81,7 @@ class ActivityObject: instance = model.find_existing(self.serialize()) or model() many_to_many_fields = {} + image_fields = {} for field in model._meta.get_fields(): # check if it's an activitypub field if not hasattr(field, 'field_to_activity'): @@ -99,11 +100,15 @@ class ActivityObject: many_to_many_fields[field.name] = value elif isinstance(model_field, ImageFileDescriptor): # image fields need custom handling - getattr(instance, field.name).save(*value, save=save) + image_fields[field.name] = value else: # just a good old fashioned model.field = value setattr(instance, field.name, value) + # if this isn't here, it messes up saving users. who even knows. + for (model_key, value) in image_fields.items(): + getattr(instance, model_key).save(*value, save=save) + if not save: # we can't set many to many and reverse fields on an unsaved object return instance