Upsert followers in add_follower to prevent IntegrityError
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -286,6 +286,23 @@ class SqlFederationService:
|
|||||||
if actor is None:
|
if actor is None:
|
||||||
raise ValueError(f"Actor not found: {username}")
|
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(
|
follower = APFollower(
|
||||||
actor_profile_id=actor.id,
|
actor_profile_id=actor.id,
|
||||||
follower_acct=follower_acct,
|
follower_acct=follower_acct,
|
||||||
|
|||||||
Reference in New Issue
Block a user