Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Length() schema validator does not interpolate #356

Open
jenstroeger opened this issue Jun 25, 2023 · 2 comments
Open

Length() schema validator does not interpolate #356

jenstroeger opened this issue Jun 25, 2023 · 2 comments

Comments

@jenstroeger
Copy link
Contributor

It looks like

min_err = _(self.min_err, mapping={'min': self.min})
raise Invalid(node, min_err)

should actually be

min_err = _(self.min_err, mapping={'min': self.min}).interpolate()
raise Invalid(node, min_err)

and likewise with max_error below. Otherwise the raised Invalid() exception will contain

Longer than maximum length ${max}
@stevepiercy
Copy link
Member

In the tests, interpolate() is called. I wonder if that is to allow translations? See Change History

@jenstroeger
Copy link
Contributor Author

Hmm, that’s an interesting choice — the raised exception doesn’t contain the final error string but I’m supposed to expand/interpolate values on it?

I wonder if that is to allow translations?

The translated string (without expanded values) is already part of the exception object, though, then why not expand its values too?

Also, it might be problematic for users to delegate .interpolate() because it might fail if the Invalid exception doesn’t contain a a TranslationString — or is it guaranteed that it does? Just feels odd to me to expect users of an exception to continue manipulating the exception message 🤔

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

No branches or pull requests

2 participants