Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mdkaifansari04
Copy link
Contributor

@mdkaifansari04 mdkaifansari04 commented Oct 30, 2025

Description:

Fixes: #4682

Found that the leaderboard was including users with empty or null usernames, which was causing a NoReverseMatch error while generating profile URLs.

Added filters in get_leaderboard to exclude such users.

.filter(username__isnull=False)
.exclude(username="")

This prevents the error and ensures only valid users are shown in the leaderboard.

Summary by CodeRabbit

Bug Fixes

  • Enhanced leaderboard data quality by filtering out entries with missing or invalid user identifiers, ensuring only legitimate user records appear in rankings.

- Filter out users with empty usernames in leaderboard view
- ci/cd break fix
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Walkthrough

Filtering logic added to LeaderboardBase.get_leaderboard method to exclude records with null or empty usernames, restricting leaderboard results to entries with valid non-empty usernames.

Changes

Cohort / File(s) Summary
Leaderboard filtering
website/views/user.py
Added query filters to LeaderboardBase.get_leaderboard: excludes records where username is null (username__isnull=False) or empty string (exclude(username="")). Behavior change only; method signature remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Minor query modification with straightforward filter logic
  • Verify that null/empty username exclusion aligns with intended leaderboard behavior
  • Confirm no unintended side effects on API responses

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
βœ… Passed checks (2 passed)
Check name Status Explanation
Title Check βœ… Passed The pull request title "Fix: Filter out users with empty usernames in leaderboard view" directly and accurately describes the primary change in the changeset. The summary confirms that the modification adds filters to the get_leaderboard method to exclude records with null or empty usernames, which aligns precisely with what the title states. The title is concise, specific, and uses clear language that would allow a teammate scanning PR history to understand the main change without ambiguity.
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
website/views/user.py (1)

421-423: Good defensive fix for the NoReverseMatch error.

The filtering logic correctly excludes users with null or empty usernames, which will prevent errors when generating profile URLs. The two separate filters make the intent clear and handle both NULL database values and empty strings.

Optional enhancement: Consider whitespace-only usernames.

If data integrity is a concern, you might also want to filter out usernames that contain only whitespace:

         .filter(
             total_score__gt=0,
             username__isnull=False,
         )
-        .exclude(username="")
+        .exclude(username="")
+        .exclude(username__regex=r'^\s+$')

Alternatively, you could simplify the filters slightly:

         .filter(
             total_score__gt=0,
-            username__isnull=False,
         )
-        .exclude(username="")
+        .exclude(Q(username__isnull=True) | Q(username="") | Q(username__regex=r'^\s+$'))
πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 906440d and fa63eb5.

πŸ“’ Files selected for processing (1)
  • website/views/user.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Run Tests
  • GitHub Check: docker-test

@DonnieBLT DonnieBLT merged commit c10fe9d into OWASP-BLT:main Oct 30, 2025
14 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

Fix: Filter out users with empty usernames in leaderboard view

2 participants