Skip to content

Validation against invalid UUID for remove-self endpoint#5968

Open
bjester wants to merge 3 commits into
learningequality:unstablefrom
bjester:fix/remove-self-invalid-uuid
Open

Validation against invalid UUID for remove-self endpoint#5968
bjester wants to merge 3 commits into
learningequality:unstablefrom
bjester:fix/remove-self-invalid-uuid

Conversation

@bjester

@bjester bjester commented Jun 10, 2026

Copy link
Copy Markdown
Member

Summary

This PR fixes an unhandled exception in ChannelUserViewSet.remove_self where malformed channel_id values 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.

References

Original: #5776
closes #5779

Reviewer guidance

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.

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.

In followup, AI was used to address remaining review feedback.

@bjester bjester requested a review from rtibblesbot June 10, 2026 19:57

@rtibblesbot rtibblesbot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, minimal fix that addresses exactly what the issue asked for.

CI checks (Python unit tests, linting, frontend build) were still pending at review time — no failures to report. No UI changes; Phase 3 skipped.

  • praise: See inline comments on implementation and tests.

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?

Reviewed the pull request diff checking for:

  • Correctness: bugs, edge cases, undocumented behavior, resource leaks, hardcoded values
  • Design: unnecessary complexity, naming, readability, comment accuracy, redundant state
  • Architecture: duplicated concerns, minimal interfaces, composition over inheritance
  • Testing: behavior-based assertions, mocks only at hard boundaries, accurate coverage
  • Completeness: missing dependencies, unupdated usages, i18n, accessibility, security
  • Principles: DRY (same reason to change), SRP, Rule of Three (no premature abstraction)
  • Checked CI status and linked issue acceptance criteria
  • For UI changes: inspected screenshots for layout, visual completeness, and consistency

if not channel_id:
return HttpResponseBadRequest("Channel ID is required.")
try:
channel_id = uuid.UUID(channel_id).hex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Normalizing to .hex before the downstream Channel.objects.get() is a nice defensive touch — it canonicalizes any valid UUID variant (with/without dashes, mixed case) into a consistent 32-char hex string, preventing a class of subtle mismatch bugs.

)
self.assertEqual(response.status_code, 400, response.content)

def test_remove_self_with_missing_channel_returns_not_found(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Good defensive coverage — the 404 test for a valid-but-nonexistent UUID confirms that the new validation block doesn't accidentally swallow legitimate Channel.DoesNotExist paths.

@bjester bjester force-pushed the fix/remove-self-invalid-uuid branch from 06e56f5 to 3a047e5 Compare June 10, 2026 21:33
@bjester bjester force-pushed the fix/remove-self-invalid-uuid branch from 6624037 to 1bfd670 Compare June 10, 2026 21:47
@bjester bjester changed the title Fix/remove self invalid UUID Validation against invalid UUID for remove-self endpoint Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid UUID in remove_self causes 500 instead of proper validation error

3 participants