Skip to content

feat(sqlalchemy): maxLength validator from char_length constraints#1170

Draft
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/char-length-maxlength-validator
Draft

feat(sqlalchemy): maxLength validator from char_length constraints#1170
aiolibsbot wants to merge 1 commit into
aio-libs:masterfrom
aiolibsbot:koan/char-length-maxlength-validator

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What

Translate char_length(col) <= N / < N check constraints into maxLength input validators.

Why

_get_validators already turned char_length(col) >= N / > N constraints into minLength validators, and it handles the full ge/gt/le/lt range for numeric bounds. But the <= / < char-length cases fell through silently — a CheckConstraint(func.char_length(col) <= N) on a Text column (no fixed .length) produced zero client-side max-length validation. This closes that asymmetry. Part of #666.

How

Added le -> maxLength(N) and lt -> maxLength(N-1) branches alongside the existing ge/gt minLength handling. The -1 for the strict < mirrors the numeric lt -> maxValue(N-1) convention. Frontend already deserializes the maxLength validator, so no admin-js change.

Testing

Extended test_check_constraints with <= and < char-length columns asserting maxLength(5) and maxLength(4). Full suite: 97 passed, 1 xfailed; the lone test_admin_view failure is pre-existing (#934) and unrelated.


Quality Report

Changes: 2 files changed, 10 insertions(+)

Code scan: clean

Tests: failed (command not found)

Branch hygiene: clean

Generated by Kōan

_get_validators translated char_length(col) >= N / > N check constraints
into minLength validators, but silently dropped the <= N / < N forms — so
a max-length CheckConstraint on a Text column (no fixed .length) produced
no client-side validation. Now symmetric with the numeric ge/gt/le/lt and
the minLength handling: <= N -> maxLength(N), < N -> maxLength(N-1).

Part of aio-libs#666. Frontend already handles the maxLength validator, so no
admin-js change is needed.
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
aiohttp_admin/backends/sqlalchemy.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1170      +/-   ##
==========================================
+ Coverage   95.56%   95.64%   +0.07%     
==========================================
  Files          21       21              
  Lines        2954     2962       +8     
  Branches      193      195       +2     
==========================================
+ Hits         2823     2833      +10     
+ Misses        105      103       -2     
  Partials       26       26              
Flag Coverage Δ
integration 81.00% <0.00%> (+0.05%) ⬆️
js 83.89% <ø> (ø)
unit 97.51% <87.50%> (+0.09%) ⬆️

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