Skip to content

fix(filler): replace timestamp filename with uuid4 to prevent race condition#199

Open
Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Gopisokk:fix/uuid-pdf-output-naming
Open

fix(filler): replace timestamp filename with uuid4 to prevent race condition#199
Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Gopisokk:fix/uuid-pdf-output-naming

Conversation

@Gopisokk
Copy link

@Gopisokk Gopisokk commented Mar 7, 2026

Summary

Fixes a race condition in src/filler.py where two concurrent requests
processed in the same second produce identical output filenames.

Root Cause

datetime.now().strftime("%Y%m%d_%H%M%S") has 1-second resolution.
Two requests in the same second → same path → second write silently
overwrites the first. The first submission's DB record then points to
wrong data, with no exception raised anywhere.

Fix

  • Extracted path generation into Filler._make_output_path() static method
  • uuid4().hex (128-bit randomness, collision probability = 2⁻¹²⁸)
  • Outputs written to outputs/ subdirectory — separates generated files
    from source templates

Testing

Added tests/test_filler.py with 4 unit tests:

  • test_make_output_path_is_unique — 500 calls, all unique paths
  • test_make_output_path_lands_in_outputs_subdir
  • test_make_output_path_extension_is_pdf
  • test_make_output_path_preserves_stem

Closes #198

…ndition

Two concurrent requests processed in the same second previously generated
identical output paths (YYYY%m%d_%H%M%S has only 1-second resolution).
The second PdfWriter.write() call silently overwrote the first, leaving
the first submission's DB record pointing to corrupted/wrong data with no
exception raised anywhere in the stack.

Fix:
- Extract path generation into Filler._make_output_path() static method
- Use uuid4().hex (128-bit randomness) instead of a timestamp
- Write outputs into an outputs/ subdirectory adjacent to the template,
  separating generated files from source templates

Also add tests/test_filler.py with four unit tests covering:
- Uniqueness of 500 generated paths (regression guard)
- Correct placement in outputs/ subdirectory
- .pdf extension
- Original template stem preserved in filename

Fixes: race condition in PDF output naming
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]: Race condition in PDF output naming — concurrent requests silently overwrite filled PDFs

1 participant