fix: add input validation across model_hub, conversions and alpha#216
Open
crazywriter1 wants to merge 2 commits intoOpenGradient:mainfrom
Open
fix: add input validation across model_hub, conversions and alpha#216crazywriter1 wants to merge 2 commits intoOpenGradient:mainfrom
crazywriter1 wants to merge 2 commits intoOpenGradient:mainfrom
Conversation
- Guard response.json() in model_hub.py upload() against HTML error pages - Replace bare Exception with RuntimeError in model_hub.py create_model and create_version - Fix create_version docstring and remove redundant except Exception: raise block - Add type guard for event_data in _conversions.py convert_to_model_output - Validate inference_contract_address format in Alpha constructor Signed-off-by: crazywriter1 <crazywriter1@users.noreply.github.com>
Author
|
Can you check this? @adambalogh |
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.
Summary
model_hub.py— Guardresponse.json()inupload()against HTML error pages: when the server returns a non-JSON response (e.g. a WAF or proxy error page), the previous code crashed withJSONDecodeError; now falls back toresponse.text. Note:create_model's successful-responseresponse.json()call (HTTP 200 path) is intentionally out of scope — a 200 response returning HTML is not a realistic failure scenario.model_hub.py— Replace bareExceptionwithRuntimeErrorincreate_modelandcreate_versionacross all raise paths; fixcreate_versiondocstring which still claimedRaises: Exception; remove redundantexcept Exception: raiseblock that served no purpose_conversions.py— Add type guard at the top ofconvert_to_model_output: ifevent_dataisNoneor not dict-like, raisesTypeErrorwith a clear message instead of an unhelpfulAttributeErrormid-functionalpha.py— Validateinference_contract_addressin theAlphaconstructor usingWeb3.is_address()so invalid addresses fail immediately at construction time with a clearValueErrorinstead of failing silently during a transactionFiles Changed
src/opengradient/client/model_hub.pysrc/opengradient/client/_conversions.pysrc/opengradient/client/alpha.pytests/client_test.pyTest Plan
uv run pytest tests/ -v→ 122 passedTestModelHubUploadErrorHandling— verifies HTML response raisesRuntimeError, JSON error response raisesRuntimeErrorwith detail messageTestConvertToModelOutputGuard— verifiesNoneand non-dict inputs raiseTypeError, empty dict returns empty outputTestAlphaAddressValidation— verifies invalid address raisesValueErrorat construction time, valid address passes, empty string raisesValueError;Web3.is_addressis called before address assignment (constructor-level validation, not checksum rule testing)