model: use is None instead of falsy check in check_default_min_max - #517
Merged
sschleemilch merged 2 commits intoMay 26, 2026
Merged
Conversation
sschleemilch
requested changes
May 5, 2026
|
|
||
| def check_default_min_max(self) -> Self: | ||
| if not self.default: | ||
| # Use an explicit None check rather than a falsy check: `not self.default` |
Collaborator
There was a problem hiding this comment.
That's pretty verbose. Just fix the if statement, which is a good catch
| ({"datatype": "uint8", "max": 100, "default": 90}, True), | ||
| ({"datatype": "uint8", "min": 10, "default": 5}, False), | ||
| ({"datatype": "uint8", "min": 10, "default": 10}, True), | ||
| # Regression: `default=0` (a falsy but valid numeric default) used to |
Collaborator
There was a problem hiding this comment.
No need for those comments. Just add the tests
Collaborator
|
MoM:
|
Collaborator
|
@SoundMatt - will you take a look at the comments from Sebastian |
Contributor
Author
|
Addressed — verbose comments removed. |
`check_default_min_max` returned early when `not self.default` was truthy. Python treats 0, False, "", and [] as falsy, so a numeric signal with `default=0` and a positive `min` (or default=0 and a negative `max`) silently bypassed the range check. The validation intended to catch invalid defaults was a no-op for those values. Switch to an explicit `self.default is None` check. The downstream loop already handles list/scalar shapes correctly; with this fix, default=0 is run through the comparison and will trigger ValidationError when out of range. Adds three regression cases to tests/test_model.py covering default=0 with various min/max bounds (the primary bug case, plus a sanity case for default=0 within bounds). Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
SoundMatt
force-pushed
the
fix/check-default-min-max-falsy
branch
from
May 22, 2026 21:39
74a66f8 to
dea2b3f
Compare
Collaborator
|
@sschleemilch - do you want to take a second look here |
sschleemilch
approved these changes
May 26, 2026
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.
Problem
check_default_min_maxinsrc/vss_tools/model.pyreturned earlywhen
not self.defaultwas truthy. Python treats0,False,"",and
[]as falsy, so a numeric signal like:…silently passed validation. Same for
default: 0with a negativemax. The intended range check was a no-op for any falsy default.Fix
The downstream loop already handles list-vs-scalar correctly; with
this fix,
default=0runs through the comparison and raisesValidationErrorwhen out of range.Test
Three new parametrize cases in
tests/test_model.py:({"datatype": "uint8", "min": 1, "default": 0}, False), # bug case ({"datatype": "int8", "max": -1, "default": 0}, False), # bug case ({"datatype": "uint8", "min": 0, "default": 0}, True), # sanityThe first two would have passed (incorrectly) before this PR. The
third confirms
default=0is still allowed when within bounds.Notes
PRs harden the same
model.pyvalidators against silent failure.scopes separable. They can land in either order without conflict.