Enhancement: Be able to enforce min_length
, max_length
, etc. for SecretString
#3786
Labels
Enhancement
This is a new feature or request
Summary
The
SecretString
feature is really nice, and other frameworks do similar things nowadays. However, unlike those other frameworks, Litestar doesn't appear to have the ability to set constraints on this type.I'd much prefer to use
SecretString
over a basicstr
for things like passwords, but there are some cases where I'm legally obligated to enforce a minimum length, so this is important.Basic Example
Using Pydantic as an example, I can do this and it all works just fine:
But when I try to achieve the same thing with Litestar:
I get an error:
My current workaround feels extremely hacky:
Ideally I'd be able to encapsulate all of this validation logic into a single field/type definition that I could then reuse multiple places.
Drawbacks and Impact
It seems to me this feature could only be a good thing.
Unresolved questions
Is there already a better way to do this than my current workaround?
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
The text was updated successfully, but these errors were encountered: