Decode byte-string fill values in get_json_serializable_value (fixes #61)#108
Open
arpitjain099 wants to merge 1 commit into
Open
Decode byte-string fill values in get_json_serializable_value (fixes #61)#108arpitjain099 wants to merge 1 commit into
arpitjain099 wants to merge 1 commit into
Conversation
Byte strings can appear in a variable's _FillValue metadata attribute and are not JSON serializable. They reached requests.put(json=...) in publish_umm_var unchanged and crashed with 'Object of type bytes is not JSON serializable'. Decode them to text so the UMM-Var record serializes. Fixes nasa#61. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
📝 WalkthroughWalkthrough
ChangesJSON serialization fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Description
Fixes #61.
As @owenlittlejohns confirmed in the issue thread, the crash comes from a byte value in umm_var_dict (a
_FillValueofb'\x00'on a MISR variable). It passes through get_json_serializable_value untouched, and then publish_umm_var'srequests.put(..., json=umm_var_dict)blows up with "Object of type bytes is not JSON serializable".That function already special-cases numpy ints and floats, so I added a bytes branch right alongside them. Byte strings are decoded with
errors='replace'so an undecodable fill value can't itself raise. If you'd rather coerce these upstream (e.g. where the FillValues list is built), I'm glad to move it.Jira Issue ID
N/A (GitHub issue #61)
Local Test Steps
Added a byte-string subtest to test_get_json_serializable_value; test_umm_var.py passes (21), ruff and black clean on the changed files.
PR Acceptance Checklist
CHANGELOG.mdupdated to include high level summary of PR changes.VERSIONupdated if publishing a release.Summary by CodeRabbit
Bug Fixes
Tests
Chores