Skip to content

fix(reports): return the new PDF link from POST /reports/pdf - #186

Merged
satishbagali merged 1 commit into
mainfrom
fix/report-pdf-stale-url
Dec 3, 2026
Merged

satishbagali merged 1 commit into
mainfrom
fix/report-pdf-stale-url

Conversation

@satishbagali

@satishbagali satishbagali commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

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_v2 stores bucket_url with a raw UPDATE and commits. Sessions are created with expire_on_commit=False (app/db/session.py), so get_by_report_id after the generator returns the same in-memory Report from the identity map, with bucket_url still None.

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 answer report.bucket_url. One file, +6/−2.

Tests

Frontend impact

None. The PWA already uses the returned URL (useReportPdf.getPdf, reports/page.tsx handleGetPdf).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where generating a PDF report could leave its download link outdated. After generation, the report now provides the refreshed link, making it easier to access the newly generated PDF. This ensures the link shown for the report reflects its latest generated version rather than a previously stored address.

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>
@satishbagali

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

After PDF generation succeeds, generate_pdf_report refreshes the existing report object and returns its updated bucket_url. The second repository lookup is removed.

Changes: PDF report response

Layer / File(s) Summary
Refresh report before response
backend/routers/animal.py
After PDF generation succeeds, the endpoint refreshes the existing report object and returns its updated bucket_url.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: aiyappa-digitalgreen

Merge Risk: Minimal · up to abdc5

The endpoint now returns the freshly generated PDF link on the first request instead of a stale null. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: POST /reports/pdf now returns the new PDF link (bucket_url). The raw summary says generate_pdf_report refreshes the report ORM object after PDF generation and returns its u…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: POST /reports/pdf now returns the new PDF link (bucket_url). The raw summary says generate_pdf_report refreshes the report ORM object after PDF generation and returns its updated bucket_url, which matches. The title is short, specific, and follows a conventional commit style. It does not cover the reason for the change (stale object from expire_on_commit=False), which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 718bf35 and abdc5b0.

Files selected for processing: 1

  • backend/routers/animal.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@satishbagali
satishbagali merged commit ad9441d into main Dec 3, 2026
6 checks passed
@satishbagali
satishbagali deleted the fix/report-pdf-stale-url branch December 3, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant