[Bugfix:RainbowGrades] Guard null bucket access in customizations#12545
[Bugfix:RainbowGrades] Guard null bucket access in customizations#12545SergioChan wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #12545 +/- ##
=========================================
Coverage 21.66% 21.66%
- Complexity 9638 9639 +1
=========================================
Files 268 268
Lines 36233 36236 +3
Branches 486 486
=========================================
+ Hits 7849 7851 +2
- Misses 27902 27903 +1
Partials 482 482
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
Updated the PR title to match the documented format constraints:
That should satisfy the type/module + subject length checks from The two existing |
|
Updated this PR’s title to:
to align with the repository’s required If the two existing Title Check failures still show up, they look like stale historical runs from the original PR open event and may need a maintainer rerun to refresh status. |
|
I've tested it thoroughly and have reached the conclusion that the instructions presented to re-create the error are not sufficient to to show malfunction. If you choose to continue working on this issue, include screenshots in demonstrating the error and re-creation steps. Once that is fulfilled feel free to re-open the PR and tag me for re-review. |
### Why is this Change Important & Necessary? Fixes #12544. The Rainbow Grades customization page crashes for some older courses when legacy `gui_customization.json` data contains: - bucket types not present in the current syllabus bucket list - `"ids": null` instead of an array The backend assumes these values are arrays and directly calls `array_filter()` or iterates using `foreach`, resulting in a PHP 8 `TypeError`. --- ### What is the New Behavior? - Bucket gradeable data is normalized to an empty array if missing or invalid - `json_bucket->ids` is normalized before iteration - Legacy bucket metadata is initialized when needed Malformed or legacy data is now treated as an empty bucket instead of causing a crash. Existing valid behavior is unchanged. #### Before (bug) Legacy customization data with `"ids": null` causes a crash on the customization page: <img width="1470" height="956" alt="Screenshot 2026-04-01 at 10 52 16" src="https://github.com/user-attachments/assets/1a9af415-d8c7-4a53-bee6-8bd8fb0ad64e" /> #### After (fixed) The same input no longer crashes and the page loads successfully: <img width="1470" height="956" alt="Screenshot 2026-04-01 at 10 54 29" src="https://github.com/user-attachments/assets/b2267620-7510-4009-9f1b-daeb52acccda" /> --- ### What steps should a reviewer take to reproduce or test the bug or new feature? 1. Create or edit `rainbow_grades/gui_customization.json` in a course directory 2. Add a legacy bucket entry such as: ```json { "gradeables": [ { "type": "legacy-bucket", "count": 1, "remove_lowest": 0, "percent": 0.25, "ids": null } ] } ``` 3. Visit: `/courses/<term>/<course>/reports/rainbow_grades_customization` 4. Before this patch: - Page crashes with: `array_filter(): Argument #1 ($array) must be of type array, null given` 5. After this patch: - Page loads successfully and treats the malformed bucket as empty --- ### Automated Testing & Documentation - Added regression test: `tests/app/models/RainbowCustomizationTester.php` - Ran: - `php vendor/bin/phpunit tests/app/models/RainbowCustomizationTester.php` - `php vendor/bin/phpunit tests/app/controllers/admin/ReportControllerTester.php` - No documentation changes required --- ### Other information - Not a breaking change - No migrations required - No security concerns - Supersedes abandoned PR #12545 --------- Co-authored-by: D'Andre Collins <[email protected]>
Why is this Change Important & Necessary?
Fixes #12544.
Old courses can contain
nullbucket entries in stored rainbow customization data. The current code passes thatnulldirectly toarray_filter, which throws a fatalTypeErrorand crashes the customization page.What is the New Behavior?
When reading an existing customization bucket, the code now normalizes missing or non-array bucket data to an empty array before filtering removed/swapped gradeables. This prevents the crash while preserving existing filtering logic for valid array inputs.
What steps should a reviewer take to reproduce or test the bug or new feature?
nullvalue (or temporarily inject one).array_filter(): Argument #1 ($array) must be of type array, null given.Automated Testing & Documentation
phpis not installed (php: command not found).Other information