Add JSON validation for project criteria submission#144
Merged
Conversation
Member
|
@copilot you got stuck. continue |
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Co-authored-by: alexeygrigorev <875246+alexeygrigorev@users.noreply.github.com>
Contributor
Author
Completed the JSON validation implementation! I added comprehensive validation for the ReviewCriteria.options field at both the model and form levels. The solution:
The exact JSON from the issue (dict with nested "options" key) will now be properly rejected with a clear error message instead of causing a 500 error. |
Copilot
AI
changed the title
[WIP] Add JSON validation for project criteria submission
Add JSON validation for project criteria submission
Jan 21, 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.
This PR adds comprehensive JSON field validation for the ReviewCriteria.options field to prevent 500 server errors when submitting incorrect JSON through the admin panel.
Problem
Users could submit incorrect JSON structure via the admin panel (e.g., a dict with nested "options" key instead of a direct list), which would cause 500 errors when the code tried to access the data expecting a specific structure.
Solution
1. Created Validator Function
File:
courses/validators/criteria_validators.pyThe
validate_review_criteria_options()function validates:2. Updated Model
File:
courses/models/project.pyAdded the validator to the ReviewCriteria model's options field.
3. Enhanced Admin Form
File:
courses/admin/course.pyUpdated CriteriaForm to:
4. Comprehensive Tests
Added 16 tests covering:
Expected Format
[ {"criteria": "Poor", "score": 0}, {"criteria": "Good", "score": 1}, {"criteria": "Excellent", "score": 2} ]Testing
Users attempting to submit invalid JSON will now see helpful error messages in the admin panel instead of getting 500 errors.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.