Skip to content

Commit fea65ea

Browse files
authored
Allow the 'key' field of Radio widgets to be null (#2300)
This fixes a bug in the parser that caused it to incorrectly reject some production data. Reported here: https://khanacademy.slack.com/archives/C01AZ9H8TTQ/p1741876983359149 Issue: none ## Test plan: `yarn test` After deployment, the number of errors on Sentry mentioning `At (root).question.widgets["radio 1"].key -- expected number, but got null` should decrease sharply. Author: benchristel Reviewers: handeyeco, Myranae Required Reviewers: Approved By: handeyeco, Myranae Checks: ✅ 8 checks were successful Pull Request URL: #2300
1 parent af6d890 commit fea65ea

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

.changeset/early-swans-brush.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@khanacademy/perseus-core": patch
3+
---
4+
5+
Bugfix: allow the 'key' field of Radio widgets to be null when parsing Perseus JSON

packages/perseus-core/src/parse-perseus-json/perseus-parsers/radio-widget.test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,21 @@ describe("parseRadioWidget", () => {
7878
),
7979
);
8080
});
81+
82+
it("allows a null key", () => {
83+
const widget = {
84+
type: "radio",
85+
key: null,
86+
graded: true,
87+
version: {
88+
major: 2,
89+
minor: 0,
90+
},
91+
options: {
92+
choices: [],
93+
},
94+
};
95+
96+
expect(parse(widget, parseRadioWidget)).toEqual(success(widget));
97+
});
8198
});

packages/perseus-core/src/parse-perseus-json/perseus-parsers/widget.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function parseWidgetWithVersion<
4545
graded: optional(boolean),
4646
alignment: optional(string),
4747
options: parseOptions,
48-
key: optional(number),
48+
key: optional(nullable(number)),
4949
version: parseVersion,
5050
});
5151
}

0 commit comments

Comments
 (0)