diff --git a/backend/app/routers/connections.py b/backend/app/routers/connections.py index a566f27..dd0b1ce 100644 --- a/backend/app/routers/connections.py +++ b/backend/app/routers/connections.py @@ -249,8 +249,11 @@ async def send_connection_request( # Extract ntfy config before commit (avoids detached SA object in background task) target_ntfy = extract_ntfy_config(target_settings) if target_settings else None + # Build response BEFORE commit — commit expires all ORM objects, and accessing + # their attributes after commit triggers lazy loads → MissingGreenlet in async SA. + response = _build_request_response(conn_request, current_user, sender_settings, target, target_settings) + await db.commit() - await db.refresh(conn_request) # ntfy push in background (non-blocking) background_tasks.add_task( @@ -260,7 +263,7 @@ async def send_connection_request( "request_received", ) - return _build_request_response(conn_request, current_user, sender_settings, target, target_settings) + return response # ── GET /requests/incoming ──────────────────────────────────────────