Skip to content

Fix public profile 404 when username differs from slug - #2762

Merged
Didayolo merged 1 commit into
codalab:fix/public-profile-username-lookupfrom
anubhavlal07:fix/public-profile-username-lookup
Nov 23, 2026
Merged

Didayolo merged 1 commit into
codalab:fix/public-profile-username-lookupfrom
anubhavlal07:fix/public-profile-username-lookup

Conversation

@anubhavlal07

@anubhavlal07 anubhavlal07 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

@ 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 as siddhant_chaudhary__ in #2761.

Root cause: PublicProfileView sets slug_url_kwarg = 'username' but keeps the default slug_field = 'slug', so it looks up User.slug == <url value>. User.save() sets slug = slugify(username), and slugify lowercases the value and strips leading and trailing _ and -. So siddhant_chaudhary__ gets the slug siddhant_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 user trailing_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 with 404 == 200.

Issues this PR resolves

Fixes #2761

A checklist for hand testing

  • Sign up (or edit a user in admin) with a username ending in __, e.g. test_user__
  • Open /user/test_user__/ while logged in: the profile loads
  • Open /profiles/user/test_user__/: redirects to the profile and it loads
  • Open /user/test_user/ (the slug): the same profile loads
  • Deleted / inactive / banned users still return 404

Any relevant files for testing

src/apps/profiles/tests/test_public_profile_page.py

Checklist

  • Code review by me
  • Hand tested by me
  • I'm proud of my work
  • Ready to merge

@Didayolo

Copy link
Copy Markdown
Member

Thank you for your contribution. We'll review it shortly.

@Didayolo

Copy link
Copy Markdown
Member

Maybe the problem also is being able to have a username ending with __, and therefore having discrepancy between the username and the slug.

I tried the following:

  1. Create an account with username hello_world__
  2. Create an account with username hello_world

And got a server error 500 at step 2.

@Didayolo
Didayolo changed the base branch from develop to fix/public-profile-username-lookup November 23, 2026 11:58
@Didayolo
Didayolo merged commit 5e978a8 into codalab:fix/public-profile-username-lookup Nov 23, 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.

Profile Page 404

2 participants