When a saved report had no PDF yet, the endpoint rendered and uploaded it, but
answered bucket_url null. The generator stores the link with a raw UPDATE and
commits; sessions use expire_on_commit=False, so selecting the row again
returned the same in-memory Report with bucket_url still None. The PWA then
said "The PDF isn't ready yet. Please try again." and only a second tap
worked ("PDF already available").
Reload the row with db.refresh(report) before answering.
Found while recording the Reports help video (step "PDF not ready yet").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
On a saved report whose PDF is not made yet, the first tap on Get PDF (report screen or a Feed Reports card) renders and uploads the PDF, but the API answers
bucket_url: null. The PWA then shows "The PDF isn't ready yet. Please try again." and the card keeps Get PDF. A second tap works ("PDF already available").Seen on Test on 2026-12-03 while recording the Reports help video (
POST /v1/animal/reports/pdf→ 200 in 2.7 s, card unchanged).Cause
rec_pdf_report_generator_v2storesbucket_urlwith a rawUPDATEand commits. Sessions are created withexpire_on_commit=False(app/db/session.py), soget_by_report_idafter the generator returns the same in-memoryReportfrom the identity map, withbucket_urlstillNone.Reproduced outside the app with SQLAlchemy 2.0.55 (same session settings, raw
UPDATE+ commit + re-select): re-select →None,refresh()→ the new URL.Fix
backend/routers/animal.py: after a successful render,await db.refresh(report)and answerreport.bucket_url. One file, +6/−2.Tests
tests/): the on-demand test used to mock a fresh second read, which hid the bug. It now models the reload, plus a regression test where every read returns the same stale object. Both fail onmainand pass on this branch.tests/unit: 2058 passed, 4 failed (the 4 known stale S3-mock failures since feat(infra,backend): Azure Blob storage for report PDFs (manual infra + configurable backend) #169–feat(deploy): write the Azure Blob storage settings into backend/.env when configured #171), 38 skipped.Frontend impact
None. The PWA already uses the returned URL (
useReportPdf.getPdf,reports/page.tsxhandleGetPdf).🤖 Generated with Claude Code
Summary by CodeRabbit