Restore profile tournament visibility for CPU-involved brackets - #21
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Horus0305
approved these changes
Jun 3, 2026
Horus0305
marked this pull request as ready for review
June 3, 2026 09:44
Copilot
AI
changed the title
[WIP] Fix tournament visibility for CPU-involved matches
Restore profile tournament visibility for CPU-involved brackets
Jun 3, 2026
There was a problem hiding this comment.
Pull request overview
This PR aims to fix a reported issue where tournaments involving CPU participants were not visible in a user’s tournament history, ensuring per-user tournament visibility remains independent from CPU-exclusion logic used in global stats/leaderboards.
Changes:
- Adds a backend test suite covering user tournament visibility when CPU players participated.
- Adjusts
get_user_tournaments()query behavior instats.py(removes the SQL pre-filter onTournamentHistory.players).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| CricketGame/backend/api/stats.py | Removes the SQL-level players filter in get_user_tournaments(). |
| CricketGame/backend/test_tournament_visibility.py | Adds tests asserting user tournament history includes CPU-involved tournaments and that persistence stores both human+CPU players. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
98
to
102
| rows = ( | ||
| db.query(TournamentHistory) | ||
| .filter(TournamentHistory.players.contains(username)) | ||
| .order_by(TournamentHistory.timestamp.desc()) | ||
| .all() | ||
| ) |
This branch was successfully deployed
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.
User profiles were missing tournaments whenever CPU participants were present due to overly restrictive tournament-query filtering. This change keeps CPU exclusion scoped to leaderboard aggregation only, while returning all tournaments a user actually participated in.
Tournament history query path
get_user_tournaments()to avoid SQL pre-filtering onTournamentHistory.players.contains(username), which could exclude valid rows.TournamentHistory.playersJSON (if username in players) so profile history includes CPU-involved tournaments without widening results to non-participants.Leaderboard CPU filtering scope
FormatStats.format != 'cpu'in/api/leaderboard).Tournament persistence coverage
save_tournament_history()persists full participant lists (human + CPU) inTournamentHistory.players.Original prompt
Tournament Visibility Bug: CPU-Involved Tournaments Not Showing in User Profile
Issue: Tournaments where the CPU reached the final (or participated at all) are not visible in the user profile, even though the human player participated.
Root Cause: In
CricketGame/backend/api/stats.py, theget_user_tournaments()endpoint (lines 96-114) should return all tournaments a player participated in, regardless of CPU involvement. However, the implementation may be incorrectly filtered.Additionally, a CPU involvement filter was added to global stats calculations, which may be interfering with tournament visibility. The
get_user_tournaments()endpoint should NOT apply CPU filtering—only the leaderboard should exclude CPU-involved matches.Expected Behavior:
/api/leaderboard(line 263:format != 'cpu'), not to individual player tournament historyFix Required:
get_user_tournaments()returns ALL tournaments where a player participated, with NO CPU filteringsave_tournament_history()TournamentHistory.playersJSON list includes both human and CPU playersThe following is the prior conversation context from the user's chat exploration (may be truncated):
User: Currently the tournaments where the CPU reached final, no matter who won, are not visible in the user profile, find the issue
Assistant: I'll help you find the issue about tournaments where the CPU reached the final not being visible in the user profile. Let me search for this in your repository.
Assistant: Let me search more broadly for issues related to tournaments and user profiles:
User: Currently the tournaments where the CPU reached final, no matter who won, are not visible in the user profile, find th issue and please fix that,I did implement something so that the start where the CPU is involved too much are not counted in the global stats so maybe that is interfering with the whole tournament issue right now
Assistant: I'll help you find and fix this issue. Let me start by exploring the repository to understand the codebase structure and locate the relevant code for tournaments and CPU stats.
Assistant: Let me try with lexical search instead:
Assistant: Let me get more details on the tournament history and stats retrieval:
Assistant: Now I can see the issue! In the
get_user_tournamentsendpoint (lines 96-114), the function filters tournaments by checking if the username is in the players list. However, when you look at line 100:This uses a string containment check on the JSON field. This works, but then on line 110, there's a secondary check:
The problem is likely that tournaments where the CPU reached the final are not being saved to the
TournamentHistorytable properly, or they're being filtered out somewhere. Let me check the save logic and the match stats logic:Assistant: Looking at the code, I found the issue! In the
get_user_tournamentsfunction inCricketGame/backend/api/stats.py, tournaments where the CPU reached the final are being filtered out due to a check that was implemented to exclude matches where the CPU is "too involved" in global stats.The Problem
The issue is in
CricketGame/backend/api/stats.pyat lines 96-114. Theget_user_tournamentsfunction queries tournaments by checking if a username is in the players list:However, this doesn't account for tournaments where CPU players participated. When you implemented the CPU involvement filtering in global stats (around line 263 in the same file where
format != 'cpu'is checked), the tournament query likely needs to also filter out CPU-involved tournaments from the profile view.The root cause is likely that the
TournamentHistory.playerslist contains CPU names, and when a user tries to view tournaments where they participated alongside CPUs that reached the final, those tournaments aren't being properly displayed because the filtering logic is too strict.The Fix
Here's the corrected version of the tournament endpoint that should be applied: