fix: When JSON dump with sort_key fails, retry without sorting#1823
fix: When JSON dump with sort_key fails, retry without sorting#1823corneliusroemer wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1823 +/- ##
==========================================
- Coverage 73.63% 73.58% -0.06%
==========================================
Files 81 81
Lines 8641 8651 +10
Branches 1765 1766 +1
==========================================
+ Hits 6363 6366 +3
- Misses 1976 1983 +7
Partials 302 302 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| if "'<' not supported" in str(e): | ||
| handle.seek(0) | ||
| handle.truncate(0) | ||
| print("WARNING: When writing JSON, could not sort JSON keys. A tree node is likely missing a name. Retrying without sorting keys.", file=sys.stderr) |
There was a problem hiding this comment.
write_json is not specific to tree node JSONs and the TypeError can also be due to other types (e.g. str vs int), so this hint might be misleading/confusing.
How about just reporting the underlying error:
| print("WARNING: When writing JSON, could not sort JSON keys. A tree node is likely missing a name. Retrying without sorting keys.", file=sys.stderr) | |
| print(f"WARNING: When writing JSON, could not sort JSON keys due to the error: {e}. Retrying without sorting keys.", file=sys.stderr) |
| if "'<' not supported" in str(e): | ||
| handle.seek(0) | ||
| handle.truncate(0) | ||
| print("WARNING: When writing JSON, could not sort JSON keys. A tree node is likely missing a name. Retrying without sorting keys.", file=sys.stderr) |
There was a problem hiding this comment.
You explained the underlying reason nicely in #1342 (comment). Based on that, should it error instead? If it warns and continues, the --output-node-data will have a "null" entry, which does not seem very useful.
"null": {
"branch_length": 0
},| @@ -1,23 +1,25 @@ | |||
| import argparse | |||
| import json | |||
There was a problem hiding this comment.
Can you revert the unnecessary diffs or propose them in a separate commit/PR?
Resolves #1086, #1342, #1822
Description of proposed changes
In refine, I got a TypeError when a node name is None. The reason json.dump errors is that we sort on keys before dumping, and None can't be sorted.
augur/augur/utils.py
Line 129 in e330d39
This PR makes it so that we:
Related issue(s)
I've encountered this error message at least 3 times over the last 3 years, making 3 separate issues (as I couldn't find the duplicates). I'm not alone though, another user commented they encountered the same error message: #1342 (comment)
Manual testing
It fixes the uncaught error for me:
Checklist