fix: handle invalid UUID in remove_self to prevent 500 and return 400#5776
fix: handle invalid UUID in remove_self to prevent 500 and return 400#5776ashnaaseth2325-oss wants to merge 3 commits intolearningequality:unstablefrom
Conversation
Signed-off-by: ashnaaseth2325-oss <ashnaaseth2325@gmail.com>
|
👋 Hi @ashnaaseth2325-oss, thanks for contributing! For the review process to begin, please verify that the following is satisfied:
Also check that issue requirements are satisfied & you ran Pull requests that don't follow the guidelines will be closed. Reviewer assignment can take up to 2 weeks. |
|
Hello @bjester |
bjester
left a comment
There was a problem hiding this comment.
Please submit issues first for anymore observed behaviors instead of opening PRs without issues. Opening issues first gives us a chance to collaborate and not waste each other's time.
This should instead validate the channel_id as a UUID first, instead of relying on implicit pathways to surface that.
|
Hello @bjester |
bjester
left a comment
There was a problem hiding this comment.
Thank you for adding the uuid check. It's much better!
I'd like to request a new unit test to cover it. Writing unit tests, you should also be able to verify whether the original ValueError can actually be reached after adding the uuid validation.
| except Channel.DoesNotExist: | ||
| return HttpResponseNotFound("Channel not found {}".format(channel_id)) | ||
| except ValueError: | ||
| return HttpResponseBadRequest("Invalid channel ID: {}".format(channel_id)) |
There was a problem hiding this comment.
Do we still need this now? Or is it dead code?
Fixes #5779
1. SUMMARY
This PR fixes an unhandled exception in
ChannelUserViewSet.remove_selfwhere malformedchannel_idvalues could trigger a 500 error. It adds proper validation handling to return a 400 Bad Request instead.The change is localized to
contentcuration/contentcuration/viewsets/user.py, aligning error handling with existing patterns in the codebase.2. FIX
3. VERIFICATION
Sending a request with a malformed
channel_id(e.g.,not-a-valid-uuid) now returns a 400 Bad Request instead of a 500 error. Valid but non existent UUIDs correctly return 404 Not Found, while valid existing IDs continue to work as expected.4. AI Usage
AI was used only to help improve the phrasing of this pull request description.
The issue identification, debugging, and implementation were done manually after reviewing the code and reproducing the behavior locally. The fix was verified to ensure correct handling of malformed, non-existent, and valid UUID inputs.