Skip to content

Return 404 when a template's PDF is missing at fill time - #758

Open
1sakshm wants to merge 1 commit into
fireform-core:developmentfrom
1sakshm:757-missing-template-pdf-404
Open

1sakshm wants to merge 1 commit into
fireform-core:developmentfrom
1sakshm:757-missing-template-pdf-404

Conversation

@1sakshm

@1sakshm 1sakshm commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #757

Problem

When a template's PDF is no longer on disk, FormService.fill_and_persist raised a plain FileNotFoundError. As a result:

  • POST /forms/fill returned 500 FORM_FILL_ERROR and logged a traceback.
  • Async jobs ended with TASK_FAILED.

Change

  • app/services/form.py: raise AppError with 404 TEMPLATE_PDF_NOT_FOUND. The detail field has {template_id, pdf_path}.
    • The check is now is_file(), so a path that points to a folder is caught here too.
    • The sync route already re-raises AppError, and the Celery task already records AppError codes, so neither needed changes.
  • contracts/path/forms.yaml: the 404 response for /forms/fill now lists the new code.

Tests

  • test_fill_form_template_file_not_found now expects the 404 and its detail, and checks that filler.fill is never called.
  • New test_task_records_missing_template_pdf runs fill_form_task in-process and checks that the job row stores TEMPLATE_PDF_NOT_FOUND.

Both tests fail on development (500 FORM_FILL_ERROR / TASK_FAILED). With this change, the full suite passes (414) and ruff check app/ is clean.

fill_and_persist raised a plain FileNotFoundError, so /forms/fill answered
500 FORM_FILL_ERROR and async jobs recorded TASK_FAILED. Raise an AppError
naming the template and path instead.

Fixes fireform-core#757

This branch has not been deployed

No deployments
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]: Filling a template whose PDF is missing returns 500 FORM_FILL_ERROR

1 participant