From 6cc3d14a2acf00c3531b86de01f3e7d4a0b27cf2 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 1 Dec 2024 08:18:10 +1300 Subject: [PATCH] avoid empty attachment list --- app/activitypub/util.py | 2 +- app/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/activitypub/util.py b/app/activitypub/util.py index e55bc4cc..ba95c3c5 100644 --- a/app/activitypub/util.py +++ b/app/activitypub/util.py @@ -1833,7 +1833,7 @@ 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 \ + 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 diff --git a/app/models.py b/app/models.py index 41ac8040..1628a12a 100644 --- a/app/models.py +++ b/app/models.py @@ -1227,7 +1227,7 @@ 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 \ + 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':