feat(sqlalchemy): NumberInput bounds and step from Numeric precision/scale#1171
Draft
aiolibsbot wants to merge 1 commit into
Draft
feat(sqlalchemy): NumberInput bounds and step from Numeric precision/scale#1171aiolibsbot wants to merge 1 commit into
aiolibsbot wants to merge 1 commit into
Conversation
…cision/scale A sa.Numeric(precision, scale) column fully defines the value range the database will accept and the smallest representable increment, but until now rendered as a bare NumberInput with no client-side bounds or step. Emit minValue/maxValue validators from precision/scale (the DB range) and a step input prop from scale. Explicit CheckConstraint bounds still win — type-derived bounds only fill in the side a constraint left open. Float is excluded: its precision counts binary digits, not decimal.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1171 +/- ##
==========================================
+ Coverage 95.56% 95.58% +0.02%
==========================================
Files 21 21
Lines 2954 2993 +39
Branches 193 205 +12
==========================================
+ Hits 2823 2861 +38
Misses 105 105
- Partials 26 27 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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:
sa.Numeric(precision, scale)columns now emit client-side value bounds and a decimal step on theirNumberInput, derived from the column type.Why: A
Numeric(5, 2)column can only hold values in±999.99, in0.01steps — the database rejects anything else. Until now these columns rendered as a bareNumberInputwith no bounds and a default step of 1, so the form happily accepted values the backend would then reject. This mirrors the existing CheckConstraint→validator translation, extended to the range the type itself guarantees.How:
_get_validators, forsa.Numeric(excludingsa.Float, whoseprecisioncounts binary digits) with aprecisionset, compute the magnitude10**(p-s) - 10**(-s)and emitminValue/maxValuevalidators. An explicitCheckConstraintbound takes precedence — the type-derived bound only fills in the side a constraint left open (no duplicate validators).stepinput prop of10**-scalewhenscale > 0.scale=0yields integer bounds and no step;Numeric()without precision derives nothing.Testing: New
test_numeric_precision_boundscovers scaled/unscaled/float/unbounded/constraint-override cases. Full suite: 98 passed, 1 xfailed. The lonetest_admin_viewfailure is pre-existing (#934), unrelated.Quality Report
Changes: 2 files changed, 61 insertions(+)
Code scan: clean
Tests: failed (command not found)
Branch hygiene: clean
Generated by Kōan