Skip to content

Keep template PDFs that are still in use when deleting a template - #739

Merged
marcvergees merged 2 commits into
fireform-core:developmentfrom
1sakshm:738-keep-shared-template-pdfs
Oct 26, 2026
Merged

marcvergees merged 2 commits into
fireform-core:developmentfrom
1sakshm:738-keep-shared-template-pdfs

Conversation

@1sakshm

@1sakshm 1sakshm commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Description

DELETE /templates/{id} always deleted the template's PDF from disk, even when it was still needed:

  • The bundled seed PDF: deleting the seeded "Manual Test Template" deleted data/inputs/file_template_manual.pdf, a file tracked in the repo. If the template table was later empty, seed_db() re-created the template on the next start, pointing at a PDF that no longer existed.
  • A PDF shared by several templates: POST /templates/create accepts any existing pdf_path, so two templates can point at the same file. Deleting one broke the other.

Changes:

  • app/core/config.py: new SEED_TEMPLATE_PDF_PATH constant, now used by seed_db() instead of the hard-coded string.
  • app/services/template.py: delete_template only unlinks the PDF if _pdf_still_needed() is false. It is "still needed" when it's the seed PDF, or when another template resolves to the same file. Paths are compared after resolving, so data/inputs/x.pdf and ./data/inputs/x.pdf count as the same file.

Everything else about deletion is unchanged: submissions, their output PDFs, and jobs are still removed, and a PDF used only by the deleted template is still deleted (the existing test_delete_template_deletes_pdf_file still passes).

Fixes #738

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  • Added two tests in tests/test_deletion.py:
    • test_delete_template_keeps_pdf_shared_with_another_template: two templates share a PDF; deleting the first keeps the file, deleting the second removes it
    • test_delete_template_keeps_seed_pdf: deleting a template that uses the seed PDF keeps the file
    • Both fail on development and pass with this change
  • Full suite: python -m pytest tests/ → 315 passed
  • ruff check app/ → all checks passed

Test Configuration:

  • Python version: 3.11
  • Docker/Compose version: N/A (tests run locally)
  • OS: Windows 11

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • The Lint workflow check passes on this PR ✅
  • The Tests workflow check passes on this PR ✅

1sakshm and others added 2 commits October 25, 2026 04:35
Deleting a template removed its PDF even when another template pointed
at the same file, or when it was the bundled seed PDF, which left the
remaining or re-seeded template with a missing file.

Fixes fireform-core#738
@marcvergees
marcvergees merged commit ea35712 into fireform-core:development Oct 26, 2026
2 checks passed
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]: Deleting a template deletes PDFs that are still in use (including the bundled seed PDF)

2 participants