Skip to content

fix: cast grading policy corretly as numbers - #273

Merged
nsprenkle merged 2 commits into
release-ulmofrom
nsprenkle/fix-grade-policy-typing
May 7, 2026
Merged

fix: cast grading policy corretly as numbers#273
nsprenkle merged 2 commits into
release-ulmofrom
nsprenkle/fix-grade-policy-typing

Conversation

@nsprenkle

Copy link
Copy Markdown
Member

Description

Fixes a typing issue in grading policies causing breakages on the progress page.

Jira - https://2u-internal.atlassian.net/browse/CR-8030

Supporting information

Some courses were running into the error below which was a result of a grading policy using strings instead of numbers for their values.

  File "/edx/app/edxapp/edx-platform/lms/djangoapps/course_home_api/progress/api.py", line 56, in with_placeholders
    scores=[0] * num_total,
           ~~~~^~~~~~~~~~~
TypeError: can't multiply sequence by non-int of type 'str'

This correctly casts numeric values in grading policies to numbers, allowing those mathematical operations to succeed, rather than fail.

Testing instructions

  1. Import a course with grading policies represented with strings rather than numbers.
  2. Load the progress page, verify breakage.
  3. Load new changes.
  4. Reload progress page, verify working.

Unit tests also updated.

Deadline

ASAP - fix for a C2 bug

Copilot AI review requested due to automatic review settings May 7, 2026 20:29
@nsprenkle
nsprenkle enabled auto-merge (squash) May 7, 2026 20:32

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes progress page breakages when course grading policies contain numeric values encoded as strings (e.g., "min_count": "2"), by casting those values to numeric types before doing math.

Changes:

  • Cast weight, drop_count, and min_count from grading policy entries to float/int when building the internal policy map.
  • Add a unit-test scenario covering grading policies with string-typed numeric fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lms/djangoapps/course_home_api/progress/api.py Cast grading-policy numeric fields to float/int to prevent type errors during placeholder/math operations.
lms/djangoapps/course_home_api/progress/tests/test_api.py Add a scenario where grading policy numeric fields are strings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lms/djangoapps/course_home_api/progress/tests/test_api.py
@jansenk

jansenk commented May 7, 2026

Copy link
Copy Markdown

I don't disagree with this change but I wonder whether or not this should be made further up the chain of responsibility, like, should this be done in CourseBlock.set_grading_policy()?

@nsprenkle
nsprenkle merged commit 50bde09 into release-ulmo May 7, 2026
63 checks passed
@nsprenkle
nsprenkle deleted the nsprenkle/fix-grade-policy-typing branch May 7, 2026 20:57
nsprenkle added a commit that referenced this pull request May 12, 2026
Fixes an issue with some courses causing the progress page to crash
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.

3 participants