Skip to content

Keep each report's PDF separate so a re-run doesn't overwrite it - #766

Closed
1sakshm wants to merge 1 commit into
fireform-core:developmentfrom
1sakshm:765-report-pdf-per-report
Closed

1sakshm wants to merge 1 commit into
fireform-core:developmentfrom
1sakshm:765-report-pdf-per-report

Conversation

@1sakshm

@1sakshm 1sakshm commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #765

Problem

ReportingService.generate_report saved the PDF as REPORTS_DIR/FireForm_Monthly_2024-07.pdf, and that name only identifies the period. Generating a report for a period that already had one overwrote the earlier report's file. The earlier report then served the newer PDF, whose numbers don't match its own stored summary / json_data.

Change

  • app/services/reporting.py: the PDF is now written to REPORTS_DIR/<report_id>/FireForm_Monthly_2024-07.pdf.
    • _generate_pdf already creates the parent folder.
    • The GET /reports/{id} route takes the download name from the file name, so it's unchanged: users still get FireForm_Monthly_2024-07.pdf.
    • Reports generated before this change keep their stored pdf_path, so they still work.

Tests

  • New test_report_pdf_not_overwritten_by_later_report_for_same_period generates July 2024 twice, with a new submission in between. It checks that:
    • the two reports have different PDF paths;
    • the first report still serves its original PDF bytes;
    • the summaries are 1 and 2;
    • the download name is unchanged.
  • On development it fails because both reports point to the same file.
  • Full suite: 458 passed. ruff check app/ is clean.

The PDF filename only names the period, so generating a report for the
same period again overwrote the earlier report's file, and the earlier
report then served the newer numbers. Store it under
REPORTS_DIR/<report_id>/ so the download name stays the same.

Fixes fireform-core#765
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.

[BUG]: Generating a report for the same period again overwrites the earlier report's PDF

2 participants