@@ -266,9 +266,17 @@ async def delete(
266266 If deletion cannot proceed immediately (has orders, subscriptions, or
267267 Stripe deletion fails), a support ticket will be created for manual handling.
268268 """
269+ # Re-fetch on write session — the guard loaded on a read session
270+ from polar .organization .repository import OrganizationRepository
271+
272+ org_repo = OrganizationRepository .from_session (session )
273+ organization = await org_repo .get_by_id (authorized .organization .id )
274+ if organization is None :
275+ raise ResourceNotFound ()
276+
269277 assert is_user (authorized .auth_subject )
270278 result = await organization_service .request_deletion (
271- session , authorized .auth_subject , authorized . organization
279+ session , authorized .auth_subject , organization
272280 )
273281
274282 return OrganizationDeletionResponse (
@@ -361,7 +369,13 @@ async def invite_member(
361369 session : AsyncSession = Depends (get_db_session ),
362370) -> OrganizationMember :
363371 """Invite a user to join an organization."""
364- organization = authorized .organization
372+ # Re-fetch on write session — the guard loaded on a read session
373+ from polar .organization .repository import OrganizationRepository
374+
375+ org_repo = OrganizationRepository .from_session (session )
376+ organization = await org_repo .get_by_id (authorized .organization .id )
377+ if organization is None :
378+ raise ResourceNotFound ()
365379
366380 # Get or create user by email
367381 user , _ = await user_service .get_by_email_or_create (session , invite_body .email )
0 commit comments