Upsert followers in add_follower to prevent IntegrityError

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-21 22:43:20 +00:00
parent 24432cd52a
commit 1d83a339b6

View File

@@ -286,6 +286,23 @@ class SqlFederationService:
if actor is None:
raise ValueError(f"Actor not found: {username}")
# Upsert: update if already following, insert if new
existing = (
await session.execute(
select(APFollower).where(
APFollower.actor_profile_id == actor.id,
APFollower.follower_acct == follower_acct,
)
)
).scalar_one_or_none()
if existing:
existing.follower_inbox = follower_inbox
existing.follower_actor_url = follower_actor_url
existing.follower_public_key = follower_public_key
await session.flush()
return _follower_to_dto(existing)
follower = APFollower(
actor_profile_id=actor.id,
follower_acct=follower_acct,