Skip to content

feat(sqlalchemy): NumberInput bounds and step from Numeric precision/scale#1171

Draft
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/numeric-precision-bounds
Draft

feat(sqlalchemy): NumberInput bounds and step from Numeric precision/scale#1171
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/numeric-precision-bounds

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What: sa.Numeric(precision, scale) columns now emit client-side value bounds and a decimal step on their NumberInput, derived from the column type.

Why: A Numeric(5, 2) column can only hold values in ±999.99, in 0.01 steps — the database rejects anything else. Until now these columns rendered as a bare NumberInput with 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:

  • In _get_validators, for sa.Numeric (excluding sa.Float, whose precision counts binary digits) with a precision set, compute the magnitude 10**(p-s) - 10**(-s) and emit minValue/maxValue validators. An explicit CheckConstraint bound takes precedence — the type-derived bound only fills in the side a constraint left open (no duplicate validators).
  • Add a step input prop of 10**-scale when scale > 0.
  • scale=0 yields integer bounds and no step; Numeric() without precision derives nothing.

Testing: New test_numeric_precision_bounds covers scaled/unscaled/float/unbounded/constraint-override cases. Full suite: 98 passed, 1 xfailed. The lone test_admin_view failure 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

…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

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.43590% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 95.58%. Comparing base (2448fd1) to head (296754b).
⚠️ Report is 168 commits behind head on master.

Files with missing lines Patch % Lines
aiohttp_admin/backends/sqlalchemy.py 92.85% 0 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
integration 80.10% <7.14%> (-0.85%) ⬇️
js 83.89% <ø> (ø)
unit 97.42% <97.43%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant