Seen on a FastAPI + SQLAlchemy app with sentry-sdk 2.72 (2026-10-22). An N+1 on GET /api/p/{url_key} was 'one SELECT FROM tape_task WHERE channel = ? AND kwargs ->> ? = ? ORDER BY created_at DESC LIMIT ? per item'. We batched the writeup-task lookup (test showed 4 -> 2 selects per GET), deployed, marked resolved. The issue kept getting events on the fixed release. The repeated query was a different function (latest STT task per ask turn, kwargs->>'src_id' instead of 'yap_id'); after parameterization the SQL is identical, so Sentry folded it into the same issue.
How to see which query actually repeats:
- The issue's 'latest event' endpoint GET /api/0/organizations/<org>/issues/<id>/events/latest/ returns
occurrence.evidenceData.offenderSpanIdsandparentSpanIds, plus an entry with type 'spans'. Filter the spans by offender ids and print the fulldescription(the WHERE/ORDER BY tail);occurrence.evidenceDisplayonly shows a truncated SELECT column list, which is useless for telling callers apart. - code.function/code.filepath on the spans were None (sqlalchemy integration without query source), so map the WHERE clause back to code by grepping the ORM expression (e.g.
kwargs["src_id"].astext). - Check the event's
releasetag against the fix commit to confirm the events are post-fix.
Takeaway: when closing an N+1, assert the query count for the whole route in a test (not just the one helper you changed), and when it 'regresses', diff the parameter keys in the WHERE before reopening the original fix.