fix: more robust casting of int / float in grading policy - #275
Merged
Conversation
nsprenkle
requested review from
alenkadev,
jansenk,
jristau1984,
michaelroytman and
mraman-2U
May 8, 2026 15:11
There was a problem hiding this comment.
Pull request overview
This PR makes grading policy parsing in the Course Home Progress API more tolerant of numeric values that are incorrectly stored as strings (including float-formatted strings like "2.0"), preventing progress page breakages caused by type errors.
Changes:
- Added
_to_float/_to_inthelpers for resilient numeric casting of grading policy fields. - Updated grading policy mapping to use these helpers for
weight,drop_count, andmin_count. - Extended progress API aggregation tests with a scenario covering float-formatted string counts (e.g.,
"1.0"/"2.0").
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lms/djangoapps/course_home_api/progress/api.py | Introduces tolerant numeric casting helpers and applies them when building the grading policy map. |
| lms/djangoapps/course_home_api/progress/tests/test_api.py | Adds/renames aggregation scenarios to cover string-int and string-float grading policy values. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| _make_subsection('Homework', 0, 1, ShowCorrectness.ALWAYS), | ||
| ], | ||
| {'avg': 1.0, 'weighted': 1.0, 'hidden': 'none', 'final': 1.0}, | ||
| ), |
michaelroytman
approved these changes
May 8, 2026
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.
Description
Better handles mistyped values in Grading Policies, as below:
{ "str_of_float_which_should_be_int": "2.0", "str_of_float_which_should_be_float": "1.234", "str_of_int_which_should_be_int": "2", "float_which_should_be_int": 2.0, "int_which_should_be_int": 2, "float_which_should_be_float": 1.234 }Previously, string representations of numbers would cause breakages. Blind casting to
floatorintcaused issues where anintrepresented as astrformatted as afloatwould cause further casting issues.Supporting information
Jira - https://2u-internal.atlassian.net/browse/AU-2934
Builds off of #273 , which added
intcasting ofstr, this further adds conversion offloatrepresented asstr(e.g.2.0) for a value that should be anint.Testing instructions
Load currently breaking progress page, verify fix causes page to work correctly.
Deadline
ASAP - Currently causing C2 learner issue.