Closed ddorian closed 1 year ago
Thanks for bringing this up and sharing your implementation.
I won't integrate this here. It would be better suited for marshmallow itself, it is not specific to flask-smorest.
Regarding the implementation itself, couldn't you use a Range
validator?
I'm wondering if it makes sense to integrate a PostgreSQL specific field in marshmallow if it is as easy for the user as specifying an existing validator.
Perhaps marshmallow-sqlalchemy could add that validator automatically or integers.
Regarding the implementation itself, couldn't you use a Range validator?
Is there a way to add a "default" validator to all instances of a class? Otherwise I'd have to repeat it often, no?
Perhaps marshmallow-sqlalchemy could add that validator automatically or integers.
Maybe.
Thank you.
You may subclass the field, like you already do, to add this validator by default.
My point was that it seemed better to me to use the existing validator that write comparisons.
Regarding marshmallow integration, see See https://github.com/marshmallow-code/marshmallow/issues/2182.
I was using https://github.com/schemathesis/schemathesis to test my openapi, and the first thing it did was to send a out-of-range bigint, that was accepted by python, but actually errored in PostgreSQL (
sqlalchemy.exc.DataError: (psycopg.errors.NumericValueOutOfRange) bigint out of range
).So I created a BigInteger field that checks that.