Skip to content

fix: more robust casting of int / float in grading policy - #275

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

fix: more robust casting of int / float in grading policy#275
nsprenkle merged 4 commits into
release-ulmofrom
nsprenkle/fix-grade-policy-typing-part-2

Conversation

@nsprenkle

Copy link
Copy Markdown
Member

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 float or int caused issues where an int represented as a str formatted as a float would cause further casting issues.

Supporting information

Jira - https://2u-internal.atlassian.net/browse/AU-2934

Builds off of #273 , which added int casting of str, this further adds conversion of float represented as str (e.g. 2.0) for a value that should be an int.

Testing instructions

Load currently breaking progress page, verify fix causes page to work correctly.

Deadline

ASAP - Currently causing C2 learner issue.

Copilot AI review requested due to automatic review settings May 8, 2026 15:10

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

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_int helpers for resilient numeric casting of grading policy fields.
  • Updated grading policy mapping to use these helpers for weight, drop_count, and min_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.

Comment thread lms/djangoapps/course_home_api/progress/tests/test_api.py
Comment thread lms/djangoapps/course_home_api/progress/api.py Outdated
Comment thread lms/djangoapps/course_home_api/progress/api.py Outdated
Copilot AI review requested due to automatic review settings May 8, 2026 16:30

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

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

_make_subsection('Homework', 0, 1, ShowCorrectness.ALWAYS),
],
{'avg': 1.0, 'weighted': 1.0, 'hidden': 'none', 'final': 1.0},
),
Comment thread lms/djangoapps/course_home_api/progress/tests/test_api.py
@nsprenkle
nsprenkle merged commit e37289f into release-ulmo May 8, 2026
68 checks passed
@nsprenkle
nsprenkle deleted the nsprenkle/fix-grade-policy-typing-part-2 branch May 8, 2026 17:05
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