flask-smorest: Exception after upgrading 0.13.1 -> 0.14.0
Hello.
Function flask_rest_api/utils.unpack_tuple_response checks that result returned is a tuple and tries to unpack it.
This is not working if i’m returning tuple-like object, for example sqlalchemy result object (which can be a tuple subclass) or namedtuple. All this objects pass isinstance(rv, tuple).
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (6 by maintainers)
OK, this one acts somewhat like a namedtuple but is not a namedtuple. Good. Let’s go for direct type check.
You can see examples in my previous messages. Also this is stated in documentation https://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.util.KeyedTuple
Example query:
Also sqlalchemy core returns lists and tuples too.
Cool, i’ll do a PR when i’ll have a time 😉
I’ll think about a better way. Also, i’ll check how pagination decorator works (did not use it yet).
I suggest you to think what is more useful for end users: have an ability to return a “flask” tuples or an ability to let the view automatically serialize response without boilerplate (for me this is a killer-feature) using a schema.