diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index e95c38fa..cd72c756 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -133,7 +133,9 @@ class UserFollowRequest(ActivitypubMixin, UserRelationship): user_object=self.user_subject, ) ).exists(): - raise IntegrityError() + raise IntegrityError( + "Attempting to follow blocked user", self.user_subject, self.user_object + ) super().save(*args, **kwargs) if broadcast and self.user_subject.local and not self.user_object.local: diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 6e58a2b2..3ee392e3 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -2,7 +2,6 @@ import urllib.parse import re from django.contrib.auth.decorators import login_required -from django.db import IntegrityError from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.views.decorators.http import require_POST @@ -23,16 +22,14 @@ def follow(request): username = request.POST["user"] to_follow = get_user_from_username(request.user, username) - try: - models.UserFollowRequest.objects.create( - user_subject=request.user, - user_object=to_follow, - ) - except IntegrityError: - pass - - if request.GET.get("next"): - return redirect(request.GET.get("next", "/")) + follow_request, created = models.UserFollowRequest.objects.get_or_create( + user_subject=request.user, + user_object=to_follow, + ) + if not created: + # this request probably failed to connect with the remote + # that means we should save to trigger a re-broadcast + follow_request.save() return redirect(to_follow.local_path)