fix(filler): replace timestamp filename with uuid4 to prevent race condition#199
Open
Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Open
fix(filler): replace timestamp filename with uuid4 to prevent race condition#199Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Gopisokk wants to merge 1 commit intofireform-core:mainfrom
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a race condition in
src/filler.pywhere two concurrent requestsprocessed 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
Filler._make_output_path()static methoduuid4().hex(128-bit randomness, collision probability = 2⁻¹²⁸)outputs/subdirectory — separates generated filesfrom source templates
Testing
Added
tests/test_filler.pywith 4 unit tests:test_make_output_path_is_unique— 500 calls, all unique pathstest_make_output_path_lands_in_outputs_subdirtest_make_output_path_extension_is_pdftest_make_output_path_preserves_stemCloses #198