Repository navigation
Fix public profile 404 when username differs from slug - #2762
Merged
Didayolo merged 1 commit intoNov 23, 2026
Conversation
Member
|
Thank you for your contribution. We'll review it shortly. |
Member
|
Maybe the problem also is being able to have a username ending with I tried the following:
And got a server error 500 at step 2. |
Didayolo
changed the base branch from
develop
to
fix/public-profile-username-lookup
November 23, 2026 11:58
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
@ mention of reviewers
@ihsaan-ullah (author of the profile redesign in #2704)
Description
The public profile page at
/user/<username>/returns 404 for some users, such assiddhant_chaudhary__in #2761.Root cause:
PublicProfileViewsetsslug_url_kwarg = 'username'but keeps the defaultslug_field = 'slug', so it looks upUser.slug == <url value>.User.save()setsslug = slugify(username), andslugifylowercases the value and strips leading and trailing_and-. Sosiddhant_chaudhary__gets the slugsiddhant_chaudhary. Most links (competition header, participant manager, task management, forums, server status, and the/profiles/user/<username>/redirect) point to/user/<username>/, so they 404 for any user whose username starts or ends with_/-, or has uppercase letters.Fix:
PublicProfileView.get_object()now looks the user up by username first and falls back to the slug. Links built from either value keep working. The deleted, inactive and banned filters still apply, because the lookup uses the view's queryset.Test: added
test_username_that_differs_from_slug_opens_the_profile. It creates a usertrailing_user__, checks that the slug differs from the username, and checks that both/user/<username>/and/user/<slug>/return 200. Without the fix it fails with404 == 200.Issues this PR resolves
Fixes #2761
A checklist for hand testing
__, e.g.test_user__/user/test_user__/while logged in: the profile loads/profiles/user/test_user__/: redirects to the profile and it loads/user/test_user/(the slug): the same profile loadsAny relevant files for testing
src/apps/profiles/tests/test_public_profile_page.pyChecklist