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

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 29, 2025

Creating a staking pool crashes with ValueError when stake_amount or days_duration form fields are submitted empty.

Root Cause

request.POST.get(key, default) only applies the default when the key is absent, not when the value is an empty string. Converting empty strings with Decimal("") or int("") raises ValueError.

Changes

Handle empty/None values before type conversion:

# Before
stake_amount = Decimal(request.POST.get("stake_amount", "0"))
days_duration = int(request.POST.get("days_duration", "7"))

# After  
stake_amount_str = request.POST.get("stake_amount") or "0"
days_duration_str = request.POST.get("days_duration") or "7"
stake_amount = Decimal(stake_amount_str)
days_duration = int(days_duration_str)

The existing ValueError handler still catches invalid formats like "abc".


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Copilot AI changed the title [WIP] Check if a fix exists for the issue Fix ValueError on empty stake_amount/days_duration in pool creation Oct 29, 2025
Copilot AI requested a review from DonnieBLT October 29, 2025 21:39
Copy link
Contributor

@copilot I have attached the complete error of the ci/cd error. can you make a fix for that.

@DonnieBLT DonnieBLT marked this pull request as ready for review October 30, 2025 04:13
@DonnieBLT
Copy link
Collaborator

@copilot I have attached the complete error of the ci/cd error. can you make a fix for that.

Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot I have attached the complete error of the ci/cd error. can you make a fix for that.

I don't see the complete error details in your comment. Could you please paste the CI/CD error message here or let me know which specific workflow is failing (pre-commit, tests, or docker-test)? That will help me identify and fix the issue.

@mdkaifansari04
Copy link
Contributor

@copilot

here is the complete error
error.yaml

@mdkaifansari04
Copy link
Contributor

@coderabbitai can you reolve this issue,

the error in in the error.yaml file, the cicd is breaking with it.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 30, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Download the error.yaml file to examine the CI/CD error
curl -L "https://github.com/user-attachments/files/23241406/error.yaml" -o error.yaml

# Display the contents of the error file
cat error.yaml

Length of output: 28211


🏁 Script executed:

#!/bin/bash
# Find the leaderboard view implementation
echo "=== Finding leaderboard view ==="
fd -t f -e py | xargs rg -l "def.*leaderboard" --type py

# Find leaderboard template
echo -e "\n=== Finding leaderboard template ==="
fd -t f -e html | xargs rg -l "leaderboard" | head -10

# Find the test file to understand what's being tested
echo -e "\n=== Finding the failing test ==="
rg -A 20 "def test_global_leaderboard" website/tests.py

Length of output: 1598


🏁 Script executed:

#!/bin/bash
# Get the leaderboard view implementation
echo "=== Leaderboard view code ==="
rg -A 50 "def leaderboard" website/views/user.py | head -100

# Get the global leaderboard template
echo -e "\n=== Leaderboard template ==="
cat website/templates/leaderboard_global.html

Length of output: 15012


🏁 Script executed:

#!/bin/bash
# Search for leaderboard view in views
echo "=== Finding leaderboard view function ==="
rg -n "def.*leaderboard" website/views/ -A 100 | grep -A 100 "def leaderboard"

# Also search in urls.py for the route
echo -e "\n=== Finding URL pattern ==="
rg "leaderboard" website/urls.py -B 2 -A 2

Length of output: 126


🏁 Script executed:

#!/bin/bash
# Find urls.py files
echo "=== Finding URL files ==="
fd "urls.py" -t f

# Search for leaderboard view more broadly
echo -e "\n=== Finding leaderboard view ==="
rg -n "^def leaderboard" --type py -A 80

# Also check for class-based views
echo -e "\n=== Checking for class-based leaderboard views ==="
rg "class.*Leaderboard" --type py -A 20

Length of output: 10305


🏁 Script executed:

#!/bin/bash
# Get the full GlobalLeaderboardView implementation
echo "=== GlobalLeaderboardView implementation ==="
rg -A 80 "class GlobalLeaderboardView" website/views/user.py

# Look for the specific context data method
echo -e "\n=== Finding complete get_context_data method ==="
ast-grep --pattern 'def get_context_data($$$) {
  $$$
}'  website/views/user.py | head -200

Length of output: 3124


@mdkaifansari04, I've identified the issue! The CI/CD is failing because the leaderboard queries are including entries with empty usernames, which causes the template to fail when trying to generate profile URLs.

The problem is in the GlobalLeaderboardView in website/views/user.py. The PR and Code Review leaderboard queries don't filter out entries with null or empty usernames.

Here's the fix:

def get_context_data(self, *args, **kwargs):
    """
    Assembles template context for the global leaderboard page, adding leaderboards and related data.

    The context includes:
    - `user_related_tags`: tags associated with user profiles.
    - `wallet`: the requesting user's Wallet if authenticated.
    - `leaderboard`: top users by total score (limited to 10).
    - `pr_leaderboard`: top repositories/users by merged pull request count (top 10).
    - `code_review_leaderboard`: top reviewers by review count (top 10).
    - `top_visitors`: user profiles ordered by daily visit count (top 10).

    Returns:
        dict: Context mapping names (as listed above) to their querysets or values.
    """
    context = super(GlobalLeaderboardView, self).get_context_data(*args, **kwargs)

    user_related_tags = Tag.objects.filter(userprofile__isnull=False).distinct()
    context["user_related_tags"] = user_related_tags

    if self.request.user.is_authenticated:
        context["wallet"] = Wallet.objects.get(user=self.request.user)

    context["leaderboard"] = self.get_leaderboard()[:10]  # Limit to 10 entries

    # Pull Request Leaderboard - Filter out entries with null/empty usernames
    pr_leaderboard = (
        GitHubIssue.objects.filter(
            type="pull_request", 
            is_merged=True,
            user_profile__user__username__isnull=False
        )
        .exclude(user_profile__user__username="")
        .values(
            "user_profile__user__username",
            "user_profile__user__email",
            "user_profile__github_url",
        )
        .annotate(total_prs=Count("id"))
        .order_by("-total_prs")[:10]
    )
    context["pr_leaderboard"] = pr_leaderboard

    # Reviewed PR Leaderboard - Filter out entries with null/empty usernames
    reviewed_pr_leaderboard = (
        GitHubReview.objects.filter(
            reviewer__user__username__isnull=False
        )
        .exclude(reviewer__user__username="")
        .values(
            "reviewer__user__username",
            "reviewer__user__email",
            "reviewer__github_url",
        )
        .annotate(total_reviews=Count("id"))
        .order_by("-total_reviews")[:10]
    )
    context["code_review_leaderboard"] = reviewed_pr_leaderboard

    # Top visitors leaderboard
    top_visitors = (
        UserProfile.objects.select_related("user")
        .filter(daily_visit_count__gt=0)
        .order_by("-daily_visit_count")[:10]
    )

    context["top_visitors"] = top_visitors

    return context

The key changes are:

  1. PR Leaderboard: Added .filter(user_profile__user__username__isnull=False) and .exclude(user_profile__user__username="")
  2. Code Review Leaderboard: Added .filter(reviewer__user__username__isnull=False) and .exclude(reviewer__user__username="")

These filters ensure that only entries with valid usernames are included in the leaderboards, preventing the NoReverseMatch error when the template tries to generate profile URLs.

Update the get_context_data method in the GlobalLeaderboardView class in website/views/user.py with this fix, and your CI/CD should pass!

@DonnieBLT DonnieBLT merged commit 21151b5 into main Nov 16, 2025
13 checks passed
@github-actions github-actions bot added the unresolved-conversations: 0 PR has 0 unresolved conversations label Nov 16, 2025
@DonnieBLT DonnieBLT deleted the copilot/check-for-fix branch November 16, 2025 03:26
Satish-Medar pushed a commit to Satish-Medar/BLT that referenced this pull request Nov 16, 2025
Fix ValueError on empty stake_amount/days_duration in pool creation
Satish-Medar pushed a commit to Satish-Medar/BLT that referenced this pull request Nov 16, 2025
Fix ValueError on empty stake_amount/days_duration in pool creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

files-changed: 1 unresolved-conversations: 0 PR has 0 unresolved conversations

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants