fix: Refactor proposal generation flow and add validation
Created by: Edouard-Legoupil
This is a comprehensive fix that addresses a multi-faceted bug causing proposal section generation to fail. The fix involves changes to both the frontend and backend.
Backend Changes:
-
Strict UUID Validation: The
proposal_idin all relevant Pydantic models (schemas.py) and API endpoints (proposals.py) is now enforced as auuid.UUIDtype. This prevents invalid strings (e.g., "undefined") from being processed and causing database errors. -
Robust Error Handling: The proposals API now has improved
try...exceptblocks to catch database and other exceptions, with better logging for easier debugging. -
load_draftFix: The/load-draftendpoint now correctly includes theproposal_idin its response, which was a source of the "undefined"proposal_idissue on the frontend.
Frontend Changes:
-
Correct Section Loading: The frontend logic in
Chat.jsxhas been refactored. ThehandleGenerateClickfunction now follows a robust save-then-load pattern. It first saves the draft (with the user-selected template), then immediately re-loads that draft to get a fresh session from the backend that contains the correct proposal structure. -
Improved State Management: This new flow ensures the
proposalstate on the frontend is always correctly initialized with the sections corresponding to the chosen template before the generation process begins, fixing a critical race condition.
These changes together ensure that the correct proposal sections are always used for generation and that the backend is resilient to invalid data.
- Does my code meet the quality standards for releasing packages?
- Does the reviewer have all the information to validate the features/issues without too much research?
- Does the customer who will validate the associated tickets have the information to do so without wasting time?
Issues to validate to close :
-
issue #
Processed issues to keep open or in progress:
-
issue #
Checklist:
-
Does the package check go local? -
Does the CI pass? -
Are the added / fixed features documented, tested? -
Are the added features / solved problems briefly presented in the PR message? -
Are the changes related to tickets / issues that I have listed in the commits and in the PR itself? -
Are the tickets in "review" mode in the Project Tracking Board? -
Does each ticket, if it is to be closed after acceptance of the PR, contain a comment that tells how to validate it?