fix: Improve edit profile function so it handles errors correctly #56
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.
This pull request modifies the edit profile functionality. All changes were implemented by María de la Salud Carrera Talaverón and David Vargas Jorba.
Previously, the
edit_profile()
function in the app/modules/profile/routes.py file obtained the user profile using theget_authenticated_user_profile
method in AuthenticationService. However, this made theprofile
variable be a function object, which resulted in en error later when we tried to obtain the user profile ID. To fix this issue, we decided to instead obtain the user profile using thecurrent_user
method imported from flask.Moreover, the form did not handle the validation errors properly, due to various reasons. Firstly, we decided to refactor the
update_profile(self, user_profile_id, form)
function in UserProfileService so it returns only the updated profile, instead of the profile plus the possible errors. The errors are then raised as an exception. This way, the aforementionededit_profile()
function had to be refactored too, so it handles the exception when needed. Continuing with the changes implemented in the service, we also decided to check every validation in the update method. Before this, the form allowed the user to save their profile even when the validations were not met. Once all the data is valid, the changes are commited; otherwise, the transaction is rolled back.Finally, the HTML code for the edit profile form did not show the possible errors properly. This was due to a missing
</p>
label in line 113 of the app/modules/profile/templates/profile/edit.html file.