fix(jetstream): use .get() for optional analysis_basis field - #16544
fix(jetstream): use .get() for optional analysis_basis field#16544abhi-0203 wants to merge 2 commits into
Conversation
fetch_experiment_data crashes with KeyError when a statistics row omits the analysis_basis field. The Statistic schema marks this field as Optional, so rows without it pass validation but break at the hard key lookup. Use .get() to safely handle missing analysis_basis — points without it will be skipped rather than crashing the entire fetch. Fixes mozilla#16535
jaredlockhart
left a comment
There was a problem hiding this comment.
Hi @abhi-0203 ! Thanks for contributing! Please add tests for this case and verify with make code_format check and then we can get this merged 🎉
|
Please also look at CONTRIBUTING.md for how we write our PRs |
|
Added tests and ran formatting. Tests verify:
Used black + isort for formatting. Let me know if anything else is needed! |
Add unit tests to verify: - Missing analysis_basis field doesn't raise KeyError - Present analysis_basis works correctly Because the fix uses .get() instead of [], we need tests to confirm both cases work as expected. Fixes mozilla#16535
428d2cc to
205f8d9
Compare
|
Updated commit to follow CONTRIBUTING.md format:
Note: couldn't run full make check locally (no Docker), but formatting verified with black + isort. |
Thank you @abhi-0203 It seems like some formatting still need to be done, give it another shot to format files please, if you encountered any issues please feel free to reach out |
Summary
Fixes #16535 —
fetch_experiment_datacrashes withKeyError: 'analysis_basis'when a statistics row omits the field.Problem
In
get_experiment_data, statistics rows are read from raw JSON and accessed with hard key lookups:The
analysis_basisfield is Optional in the Statistic schema, so rows that omit it pass Pydantic validation cleanly but crash at the dictionary lookup. This causesfetch_experiment_datato fail for older experiments whose analysis results don't include this field.Fix
Replace
point["analysis_basis"]withpoint.get("analysis_basis")on both comparison lines (ENROLLMENTS and EXPOSURES). When the field is missing,.get()returnsNone, which won't match either basis — the point is silently skipped, which is the correct behavior for incomplete data.Validation
point["analysis_basis"]raisesKeyErrorwhen the field is absentpoint.get("analysis_basis")returnsNone, allowing the comparison to safely skip the pointanalysis_basis