Skip to content

Fix summary to handle pending status properly#4582

Open
estyxx wants to merge 1 commit intomainfrom
grants/fix-summary
Open

Fix summary to handle pending status properly#4582
estyxx wants to merge 1 commit intomainfrom
grants/fix-summary

Conversation

@estyxx
Copy link
Member

@estyxx estyxx commented Feb 14, 2026

What

ToDo

@estyxx estyxx self-assigned this Feb 14, 2026
@vercel
Copy link

vercel bot commented Feb 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pycon Ready Ready Preview Feb 14, 2026 0:33am

@claude
Copy link
Contributor

claude bot commented Feb 14, 2026

This PR adds database-level handling for grants where pending_status is NULL by using Coalesce to fall back to status. However, there are several issues:

Testing & Coverage

Missing test coverage: The PR doesn't add tests for the edge case it's fixing (grants with pending_status=NULL). The existing tests in test_summary.py all explicitly set both status and pending_status to the same value, so they wouldn't catch this bug.

Add a test case like:

def test_grant_summary_with_null_pending_status():
    conference = ConferenceFactory()
    GrantFactory.create_batch(
        3, 
        conference=conference,
        status="approved",
        pending_status=None  # This is the edge case
    )
    summary = GrantSummary().calculate(conference_id=conference.id)
    assert summary["status_totals"]["approved"] == 3

Architecture & Design

Inconsistent implementation: The fix handles most aggregations at the database level using effective_status annotation, but _aggregate_data_by_reimbursement_category (lines 185-189) uses a different approach - it loads GrantReimbursement objects and accesses r.grant.current_or_pending_status property. This creates two different patterns for solving the same problem:

  1. Most methods: Database-level Coalesce("pending_status", "status")
  2. Reimbursement method: Python property current_or_pending_status

The reimbursement approach triggers additional queries since each r.grant.current_or_pending_status access requires the grant object to be loaded (even with select_related). For consistency and clarity, consider applying the same annotated effective_status to the reimbursement queryset.

Performance

N+1 query in _aggregate_financial_data_by_status: Line 169 filters grants by effective_status, but effective_status is a database annotation on filtered_grants, not a real field. This means .filter(effective_status=status[0]) won't work as intended - Django can't filter on annotations in subsequent filters. This will likely raise a FieldError or produce incorrect results.

You need to either:

  1. Filter before annotating, or
  2. Use conditional aggregation with Case/When to aggregate by status in a single query

@codecov
Copy link

codecov bot commented Feb 14, 2026

Codecov Report

❌ Patch coverage is 76.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.52%. Comparing base (585bb96) to head (a97b322).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4582   +/-   ##
=======================================
  Coverage   92.52%   92.52%           
=======================================
  Files         357      357           
  Lines       10690    10692    +2     
  Branches      812      812           
=======================================
+ Hits         9891     9893    +2     
  Misses        687      687           
  Partials      112      112           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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