Fix MissingGreenlet 500 error on GET /api/campaigns

Add selectinload(Campaign.agency) to get_with_proof_counts query so the
agency relationship is eagerly loaded. Without it, accessing campaign.agency.name
in the route triggered a lazy load in an async context, raising
sqlalchemy.exc.MissingGreenlet and returning HTTP 500.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Vadym Samoilenko 2026-03-02 12:17:12 +00:00
parent 3a66286900
commit 46e7de5695

View file

@ -114,6 +114,7 @@ class CampaignRepository:
func.count(Proof.id).label("proof_count"),
)
.outerjoin(Proof)
.options(selectinload(Campaign.agency))
.group_by(Campaign.id)
)
if agency_id: