From ec91e6c7d2eed61655e51787be47a7aaead8affa Mon Sep 17 00:00:00 2001 From: freamon Date: Sat, 30 Nov 2024 14:20:19 +0000 Subject: [PATCH] Bugfix for posts with empty attachments --- app/activitypub/util.py | 6 ++++-- app/models.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index e55bc4cc..cd93b428 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1833,8 +1833,10 @@ def update_post_from_activity(post: Post, request_json: dict): # Links old_url = post.url new_url = None - if 'attachment' in request_json['object'] and isinstance(request_json['object']['attachment'], list) and \ - 'type' in request_json['object']['attachment'][0]: + if ('attachment' in request_json['object'] and + isinstance(request_json['object']['attachment'], list) and + len(request_json['object']['attachment']) > 0 and + 'type' in request_json['object']['attachment'][0]): if request_json['object']['attachment'][0]['type'] == 'Link': new_url = request_json['object']['attachment'][0]['href'] # Lemmy < 0.19.4 if request_json['object']['attachment'][0]['type'] == 'Document': diff --git a/app/models.py b/app/models.py index 41ac8040..8f0d0945 100644 --- a/app/models.py +++ b/app/models.py @@ -1227,8 +1227,10 @@ class Post(db.Model): if blocked_phrase in post.body: return None - if 'attachment' in request_json['object'] and isinstance(request_json['object']['attachment'], list) and \ - 'type' in request_json['object']['attachment'][0]: + if ('attachment' in request_json['object'] and + isinstance(request_json['object']['attachment'], list) and + len(request_json['object']['attachment']) > 0 and + 'type' in request_json['object']['attachment'][0]): alt_text = None if request_json['object']['attachment'][0]['type'] == 'Link': post.url = request_json['object']['attachment'][0]['href'] # Lemmy < 0.19.4