Skip to content

[Bugfix:RainbowGrades] Handle null bucket data#12664

Merged
bmcutler merged 17 commits into
Submitty:mainfrom
not-so-shubh:fix-rainbow-null-bucket
Jun 8, 2026
Merged

[Bugfix:RainbowGrades] Handle null bucket data#12664
bmcutler merged 17 commits into
Submitty:mainfrom
not-so-shubh:fix-rainbow-null-bucket

Conversation

@not-so-shubh

@not-so-shubh not-so-shubh commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

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:

Screenshot 2026-04-01 at 10 52 16

After (fixed)

The same input no longer crashes and the page loads successfully:

Screenshot 2026-04-01 at 10 54 29

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:
{
  "gradeables": [
    {
      "type": "legacy-bucket",
      "count": 1,
      "remove_lowest": 0,
      "percent": 0.25,
      "ids": null
    }
  ]
}
  1. Visit:
    /courses/<term>/<course>/reports/rainbow_grades_customization

  2. Before this patch:

    • Page crashes with:
      array_filter(): Argument #1 ($array) must be of type array, null given
  3. 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

Copilot AI review requested due to automatic review settings March 27, 2026 17:56
@github-project-automation github-project-automation Bot moved this to Seeking Reviewer in Submitty Development Mar 27, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Seeking Reviewer to In Review in Submitty Development Mar 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash on the Rainbow Grades customization page when older gui_customization.json files contain legacy bucket types and/or ids: null, by normalizing those fields to empty arrays instead of iterating/filtering null.

Changes:

  • Normalize missing/invalid bucket gradeable data before array_filter() usage in buildCustomization().
  • Normalize json_bucket->ids before iterating in multiple code paths (percent overrides, bucket reordering, per-gradeable curves).
  • Add a regression unit test covering legacy bucket types and ids: null.

Reviewed changes

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

File Description
site/app/models/RainbowCustomization.php Adds normalization helpers and replaces unsafe direct access/iteration that could crash on legacy JSON data.
site/tests/app/models/RainbowCustomizationTester.php Adds a regression test ensuring legacy null buckets/ids don’t crash and are treated as empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@not-so-shubh not-so-shubh changed the title [Bugfix:RainbowGrades] Handle legacy null bucket data in customization [Bugfix:RainbowGrades] Handle null bucket data Mar 27, 2026
@hyeenaa

hyeenaa commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

Hey @not-so-shubh , thank you for your contribution!

Please remember use our PR description template:
https://raw.githubusercontent.com/Submitty/Submitty/refs/heads/main/.github/PULL_REQUEST_TEMPLATE.md

Once this pull request adheres to all Submitty conventions, we will proceed with a full review.

@not-so-shubh

Copy link
Copy Markdown
Contributor Author

@hyeenaa Updated the PR description to follow the Submitty template. Thanks!

@hyeenaa

hyeenaa commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

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.

@hyeenaa hyeenaa closed this Mar 31, 2026
@not-so-shubh

Copy link
Copy Markdown
Contributor Author

@hyeenaa I’ve updated the PR with clearer reproduction steps and added before/after screenshots demonstrating the issue and fix. Please feel free to re-review!

@hyeenaa hyeenaa reopened this Apr 3, 2026
@hyeenaa
hyeenaa self-requested a review April 7, 2026 19:30
@hyeenaa

hyeenaa commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

@not-so-shubh Thank you for providing more context, I was able to re-create the issue on the main branch and so far, your PR fixes the identified problems. I'm going to follow through with my review.

@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.67568% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 21.66%. Comparing base (249b9c9) to head (dbd80bd).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main   #12664      +/-   ##
============================================
+ Coverage     21.62%   21.66%   +0.04%     
- Complexity     9824     9839      +15     
============================================
  Files           268      268              
  Lines         36816    36847      +31     
  Branches        490      490              
============================================
+ Hits           7960     7983      +23     
- Misses        28370    28378       +8     
  Partials        486      486              
Flag Coverage Δ
autograder 21.32% <ø> (ø)
js 2.02% <ø> (ø)
migrator 100.00% <ø> (ø)
php 20.72% <75.67%> (+0.05%) ⬆️
python_submitty_utils 80.08% <ø> (ø)
submitty_daemon_jobs 91.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dagemcn dagemcn moved this from In Review to Seeking Reviewer in Submitty Development Apr 10, 2026
@automateprojectmangement automateprojectmangement Bot moved this from Seeking Reviewer to In Review in Submitty Development Apr 10, 2026

@hyeenaa hyeenaa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing, this PR solves the initial problem that was causing the breakage, which was having a capital "Tests" in the type category in the rainbow grades buckets. The page no longer crashes when case isn't matched. Instead, it changes the bucket type to be force-capitalized when rendering the items. This is a good approach, my only worry is that it will not tell the user when a null bucket is present. I would suggest adding an error message when a null value is in a bucket is detected before reverting, just to nudge the user.

@github-project-automation github-project-automation Bot moved this from In Review to Work in Progress in Submitty Development Apr 10, 2026
@not-so-shubh

Copy link
Copy Markdown
Contributor Author

Pushed an update that keeps the current normalization behavior, so malformed legacy bucket data still loads safely instead of crashing. I also added a non-blocking warning on the customization page when malformed legacy bucket data is detected (for example, a null ids value or an unknown bucket type), and extended the tests to cover both the recovery behavior and the warning being passed through the render path.

@github-actions github-actions Bot added the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Apr 29, 2026
@hyeenaa
hyeenaa self-requested a review April 30, 2026 19:35
@automateprojectmangement automateprojectmangement Bot moved this from Work in Progress to In Review in Submitty Development Apr 30, 2026
@hyeenaa

hyeenaa commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

can you resolve your merge conflicts with the main branch? after then your change should be approved fully.

@not-so-shubh

Copy link
Copy Markdown
Contributor Author

@hyeenaa I’ve resolved the merge conflicts with main and pushed the updated branch.

@dandrecollins07-ctrl dandrecollins07-ctrl self-assigned this Jun 3, 2026

@dandrecollins07-ctrl dandrecollins07-ctrl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested using a gui_customization.json containing a legacy bucket with "ids": null. The page now loads successfully and displays the warning message instead of generating a PHP warning. Also resolved the merge conflict in RainbowCustomization.php and verified the fix after updating the branch with the latest main.
The remaining PHPUnit failure appears unrelated to this change.

Approving.

@github-actions github-actions Bot removed the Abandoned PR - Needs New Owner No activity on PR for more than 2 weeks -- seeking new owner to complete label Jun 4, 2026

@mattLif mattLif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and changes look good. Was able to reproduce error on main, and PR branch fixes error. Only thing I notices is that I got 3 warning messages instead of 1, but that seems to only be an issue on my machine. I approve these changes.

@bmcutler
bmcutler merged commit ec65ad9 into Submitty:main Jun 8, 2026
24 of 26 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in Submitty Development Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

rainbow grades customization null/array error

7 participants