You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm in a situation where I use flask_accepts in association with flask_marshmallow and marshmallow_sqlalchemy.
Basically, all schemas that I define are not constructed from marshmallow base Schema class directly but from another class SQLAlchemySchema (which itself inherits from marshmallow base Schema). In that configuration, when trying to use these Schemas in a Nested field, flask_accepts throws a TypeError as seen in #39: "Unknown type for marshmallow model field was used."
Long story short after looking into it, I can see that SQLAlchemySchema class uses its own metaclass (inherited from marshmallow SchemaMeta) which prevents #40 from working as it uses isinstance to check the type of the provided Schema.
So I'm not sure of the direction to take here: always providing an instance of the schema will do the trick and we can leave it as it is, but I feel that it's not necessarily the best practice in term of memory usage. What do you think ?
I totally agree that issubclass would be more suitable and would be more than happy to accept a PR. Just add a test that asserts behavior works as intended if you provide either type of Schema and we should be good to go.
Hi,
This refers to #39 and #40
I'm in a situation where I use flask_accepts in association with flask_marshmallow and marshmallow_sqlalchemy.
Basically, all schemas that I define are not constructed from marshmallow base Schema class directly but from another class SQLAlchemySchema (which itself inherits from marshmallow base Schema). In that configuration, when trying to use these Schemas in a Nested field, flask_accepts throws a TypeError as seen in #39: "Unknown type for marshmallow model field was used."
Long story short after looking into it, I can see that SQLAlchemySchema class uses its own metaclass (inherited from marshmallow SchemaMeta) which prevents #40 from working as it uses
isinstance
to check the type of the provided Schema.In example (simplified), we have:
which leads to the following:
and causes the error because
type(SQLAlchemySchema)
returnsSQLAlchemyMeta
and notSchemaMeta
.I think we can solve this by using
issubclass
instead ofisinstance
in #40, which would give:I've implemented this change in my project and all seems to work fine.
I'm more than willing to make a PR for this but I'd like to have feedback on my analysis and make sure I did not miss anything.
The text was updated successfully, but these errors were encountered: