fix: return False from is_legal_dimension instead of raising TypeError - #3760
Open
shashvat-singham wants to merge 1 commit into
Open
fix: return False from is_legal_dimension instead of raising TypeError#3760shashvat-singham wants to merge 1 commit into
shashvat-singham wants to merge 1 commit into
Conversation
int() raises TypeError, not ValueError, for a type it cannot convert at
all, so is_legal_dimension only caught half of its failure cases. For
None, a list or a dict the TypeError propagated out of check_pass_param
instead of being turned into a ParamError:
>>> check_pass_param(dimension=None)
TypeError: int() argument must be a string, a bytes-like object or a
real number, not 'NoneType'
Every sibling validator reports the same input cleanly, e.g.
>>> check_pass_param(topk=None)
ParamError: <ParamError: (code=1, message=`topk` value None is illegal)>
Catch TypeError as well so the checker reports an illegal parameter.
Signed-off-by: shashvat-singham <shashvat.singham@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: shashvat-singham The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @shashvat-singham! It looks like this is your first PR to milvus-io/pymilvus 🎉 |
|
Tick the box to add this pull request to the merge queue (same as
|
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_legal_dimensiononly catchesValueErroraround itsint()call, butint()raisesTypeError— notValueError— for a type it cannot convert at all. So the exception escapescheck_pass_paraminstead of being reported as an illegal parameter:Same for
[],{}and any other non-numeric object. Every sibling validator handles the identical input cleanly, which is what makes this look unintended rather than deliberate:is_legal_porthas the sameint()-in-a-tryshape but guards withisinstance(port, (str, int))first, so it is unaffected.Fix
Catch
TypeErroralongsideValueErrorso the function returnsFalseandcheck_pass_paramraisesParamErrorlike every other parameter.Tests
Added
test_check_pass_param_invalid_dimensiontotests/unit/test_check.py, parametrised overNone,[],{}andobject(). All four fail onmasterwithTypeErrorand pass with the change.The one failure is
TestGetCommit::test_get_commit, which asserts on git metadata that isn't present in my shallow clone — it fails identically on a cleanmasterhere, unrelated to this change.Note
I deliberately kept this to the reachable case.
is_correct_date_strhas the sameexcept ValueErrorshape and would also raise on non-strinput, but its only caller (parser_range_date) checksisinstance(date, str)first, so it isn't reachable today — happy to tighten it too if you'd prefer them consistent.Separately,
is_legal_dimensioncurrently also returnsTruefor1.5,Trueand"8"sinceint()accepts all of them. That's a wider behaviour question than a crash fix, so I left it alone; let me know if you want a follow-up.