Skip to content

fix: leaderboard recalculation and migration crash on fresh DB#426

Open
lifeofagct wants to merge 7 commits intogenlayer-foundation:devfrom
lifeofagct:dev
Open

fix: leaderboard recalculation and migration crash on fresh DB#426
lifeofagct wants to merge 7 commits intogenlayer-foundation:devfrom
lifeofagct:dev

Conversation

@lifeofagct
Copy link

@lifeofagct lifeofagct commented Mar 17, 2026

This PR fixes two bugs from FIXES.md and repairs the full test suite (8/8 tests now pass).

Bug 1 - Migration 0037 crashes on fresh DB
0037_seed_featured_content.py used User.objects.get() which throws DoesNotExist
on any fresh install, developer setup, or CI pipeline. Fixed with filter().first()
and an early return guard.

Bug 2 - Hardcoded leaderboard types in recalculate_all_leaderboards()
leaderboard/models.py iterated a hardcoded list of leaderboard types when updating
ranks. Any future type added to LEADERBOARD_CONFIG would silently never get its ranks
updated. Fixed by replacing the list with LEADERBOARD_CONFIG.keys().

Test suite fixes

  • setUp now correctly handles contribution types that already exist from migrations
  • Added missing builder-welcome/builder types and multipliers needed by ensure_builder_status()
  • Graduation tests now create a Validator profile before the graduation contribution
  • user3 visibility handling fixed to work with the model's contribution guard
  • Fixed stale object reference in test_frozen_graduation_points
  • Fixed test_update_leaderboard_command to properly simulate stale multiplier data

Bug 3 - Wrong labels for Validator Waitlist users in RoleView
Waitlist users on the profile page incorrectly showed "Validator Journey",
"Total validator points" and "Validator Rank" instead of waitlist-specific
labels. Added derived variables (journeyTitle, pointsLabel, rankLabel)
that switch based on the existing isWaitlist prop.

Bug 4 - Validator Creation Shortcut not creating Validator Contribution
The admin shortcut in contributions/admin.py created a Validator profile
without the required 'validator' badge contribution, meaning the user
never appeared on the validator leaderboard.

Fix:

  • Changed Validator.objects.create() to get_or_create() (idempotent)
  • Added logic to create the 'validator' badge contribution (1 point)
    if it doesn't already exist

Also added validators/tests/test_validator_creation.py with 5 tests:

  1. Bare Validator.objects.create() does not auto-create a contribution
  2. Fixed creation logic creates both Validator profile and badge
  3. User appears on validator leaderboard after creation
  4. Duplicate badge not created on second call (idempotent)
  5. Full graduation flow: waitlist user moves to validator leaderboard

Files changed:

  • backend/contributions/migrations/0037_seed_featured_content.py
  • backend/leaderboard/models.py
  • backend/leaderboard/tests/test_recalculation.py
  • frontend/src/components/profile/RoleView.svelte
  • backend/contributions/admin.py
  • backend/validators/tests/test_validator_creation.py

Refactor test setup for leaderboard recalculation to ensure default values for contribution types and categories are updated correctly. Adjust contributions and assertions in various test cases to reflect changes in points and visibility.
Refactor validator creation and contribution logic to ensure a validator profile is created if it doesn't exist, and to handle contribution creation for the validator badge.
Add tests for validator creation and leaderboard updates.
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.

1 participant