Reject bool where a plain int is expected in _is_valid#2088
Open
NishchayMahor wants to merge 1 commit into
Open
Reject bool where a plain int is expected in _is_valid#2088NishchayMahor wants to merge 1 commit into
NishchayMahor wants to merge 1 commit into
Conversation
bool is a subclass of int, so isinstance(True, int) is True and _is_valid accepted a bool wherever a bare int was expected (e.g. query limit/offset/ autocut), silently coercing True/False to 1/0 instead of raising WeaviateInvalidInputError. Guard the int case, mirroring the bool/int fix in config.py from weaviate#2077. Adds a validator unit-test case.
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
|
To avoid any confusion in the future about your contribution to Weaviate, we work with a Contributor License Agreement. If you agree, you can simply add a comment to this PR that you agree with the CLA so that we can merge. |
Author
|
I agree with the CLA. |
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.
What
_is_validinweaviate/validator.pyends withreturn isinstance(value, expected). Becauseboolis a subclass ofint,isinstance(True, int)isTrue, so aboolpasses validation wherever a bareintis expected:Real call sites hit this — e.g.
query.pyvalidateslimit/offset/autocutas[int, None]. So:silently passes validation and sends
True(coerced to1) instead of raisingWeaviateInvalidInputError. This is the same class of bug that #2076 reported and #2077 fixed inconfig.py/util.py(... and not isinstance(x, bool)); this is the unguarded sibling site in the validator.Fix
Guard the
intcase at the terminal return, so aboolis rejected where a plainintis expected:bool-typed expectations (_is_valid(bool, True)) and all other types are unaffected.Testing
Added a case to the existing parametrized
test_validatorintest/collection/test_validator.py:It fails on
mainand passes with the fix (verified). The suite is fully offline (no DB/Docker), and the existing(1.0, [int], True)case establishes the same "reject the wrong numeric type" pattern.