marshmallow-code / flask-smorest

DB agnostic framework to build auto-documented REST APIs with Flask and marshmallow
https://flask-smorest.readthedocs.io
MIT License
651 stars 72 forks source link

Biginteger field #549

Closed ddorian closed 1 year ago

ddorian commented 1 year ago

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.

lafrech commented 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.

ddorian commented 1 year ago

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.

lafrech commented 12 months ago

You may subclass the field, like you already do, to add this validator by default.

lafrech commented 12 months ago

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.