Skip to content

Validate MIN_NUMBER_OF operator values#3531

Open
cp-at-mit wants to merge 5 commits intomainfrom
11010-program-req_tree-allows-negative-numbers-in-minimum-of
Open

Validate MIN_NUMBER_OF operator values#3531
cp-at-mit wants to merge 5 commits intomainfrom
11010-program-req_tree-allows-negative-numbers-in-minimum-of

Conversation

@cp-at-mit
Copy link
Copy Markdown
Contributor

What are the relevant tickets?

https://github.com/mitodl/hq/issues/11010

Description (What does it do?)

Add validation to ensure MIN_NUMBER_OF operator values are numeric and >= 1. In courses/forms.py: add a minimum: 1 to the schema default, enforce presence and numeric/positive checks in ProgramAdminForm._validate_elective_value_presence, and fix a traversal bug to check the child's operator field. In courses/models.py: add ProgramRequirement.clean() to validate operator_value at the model level and raise descriptive ValidationError messages for non-numeric or <1 values. These changes prevent invalid/negative elective minimums at both form and model layers.

How can this be tested?

Attempt to create a new program or edit an existing program. Enter a negative number for the "minimum number" option in the electives section of the program in Django Admin.

Add validation to ensure MIN_NUMBER_OF operator values are numeric and >= 1. In courses/forms.py: add a minimum: 1 to the schema default, enforce presence and numeric/positive checks in ProgramAdminForm._validate_elective_value_presence, and fix a traversal bug to check the child's operator field. In courses/models.py: add ProgramRequirement.clean() to validate operator_value at the model level and raise descriptive ValidationError messages for non-numeric or <1 values. These changes prevent invalid/negative elective minimums at both form and model layers.
@github-actions
Copy link
Copy Markdown

OpenAPI Changes

Show/hide ## Changes for v0.yaml:
## Changes for v0.yaml:
No changes detected

## Changes for v1.yaml:
No changes detected

## Changes for v2.yaml:
No changes detected

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@cp-at-mit cp-at-mit marked this pull request as ready for review April 28, 2026 17:50
@gumaerc gumaerc self-assigned this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants