-
Notifications
You must be signed in to change notification settings - Fork 1
fix: tolerate a non-dict evidence_json on findings read (no more 500) #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """`coerce_evidence` / `is_verified` must tolerate a non-dict `evidence_json`. | ||
|
|
||
| `Finding.evidence_json` is a JSON column, so a healthy row reads back as a dict. But a | ||
| legacy/hand-edited/double-encoded row can deserialize to a *string* (or other scalar), and | ||
| the many `(evidence or {}).get(...)` read sites would then raise `AttributeError: 'str' | ||
| object has no attribute 'get'` — one bad row 500ing a whole findings listing. These guard | ||
| that the read path coerces defensively (and recovers a double-encoded dict where it can). | ||
| """ | ||
|
|
||
| import json | ||
|
|
||
| from hexgraph.engine.findings.findings import coerce_evidence, is_verified | ||
|
|
||
| _VERIFIED = {"extra": {"verification": {"verified": True}}} | ||
|
|
||
|
|
||
| def test_coerce_passes_dicts_through_unchanged(): | ||
| ev = {"extra": {"assurance": {"standard": "static"}}} | ||
| assert coerce_evidence(ev) is ev | ||
|
|
||
|
|
||
| def test_coerce_recovers_double_encoded_dict(): | ||
| # A JSON column handed a string stores it double-encoded; it reads back as that string. | ||
| assert coerce_evidence(json.dumps(_VERIFIED)) == _VERIFIED | ||
|
|
||
|
|
||
| def test_coerce_degrades_non_object_to_empty_dict(): | ||
| assert coerce_evidence("not json at all") == {} # unparseable string | ||
| assert coerce_evidence("[1, 2, 3]") == {} # valid JSON but not an object | ||
| assert coerce_evidence(None) == {} | ||
| assert coerce_evidence(42) == {} | ||
|
|
||
|
|
||
| def test_is_verified_handles_string_evidence_without_raising(): | ||
| # The exact crash: a string evidence used to blow up the project endpoint. | ||
| assert is_verified("not json at all") is False | ||
| assert is_verified(json.dumps(_VERIFIED)) is True | ||
| assert is_verified(json.dumps({"extra": {"verification": {"verified": False}}})) is False | ||
| assert is_verified(None) is False | ||
| assert is_verified(_VERIFIED) is True |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.