Fix: Correctly serialize JSON for database updates
Created by: Edouard-Legoupil
This commit fixes a TypeError that occurred when saving proposal sections to the database. The error was caused by passing a Python dictionary to the database driver instead of a JSON string.
The process_section function in backend/api/proposals.py has been refactored to ensure the generated_sections dictionary is always serialized to a JSON string using json.dumps() before being passed to the database.
Additionally, this commit includes several improvements to the codebase:
-
The database update logic in
process_sectionhas been centralized to handle both new and regenerated content consistently. -
Redundant database update logic has been removed from
backend/utils/proposal_logic.py. -
The test suite has been significantly overhauled to use a real in-memory SQLite database instead of mocks, providing more reliable and realistic testing.
-
All relevant tests have been updated to use the new test database and an authenticated client fixture.
-
Added
pytest-mockto the testing dependencies. -
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?