Use ModelSchema.session setter rather than OPTIONS_CLASS#111
Use ModelSchema.session setter rather than OPTIONS_CLASS#111antgel wants to merge 1 commit intomarshmallow-code:devfrom
Conversation
There was a problem hiding this comment.
It does look like the current code is incorrect, I'm not sure this is the right approach. This isn't actually using the setter; it's overriding the session attribute on the ModelSchema class, which means that the sqla_session class Meta option won't be respected.
This will require more investigation. I don't have time to look into it more closely right now. In the meantime, it'd be helpful to have some test cases, or even just a code snippet to reproduce the issue.
|
I have the |
ma.init_app(app) replace DummySession() by db.session but its too late, schemas have already been created, so replace it as soon as ma have been initialized. marshmallow-code/flask-marshmallow#44 marshmallow-code/flask-marshmallow#74 marshmallow-code/flask-marshmallow#111
ma.init_app(app) replace DummySession() by db.session but its too late, schemas have already been created, so replace it as soon as ma have been initialized. marshmallow-code/flask-marshmallow#44 marshmallow-code/flask-marshmallow#74 marshmallow-code/flask-marshmallow#111
ma.init_app(app) replace DummySession() by db.session but its too late, schemas have already been created, so replace it as soon as ma have been initialized. marshmallow-code/flask-marshmallow#44 marshmallow-code/flask-marshmallow#74 marshmallow-code/flask-marshmallow#111
When I use webargs with flask-marshmallow, there is an issue whereby webargs calls
schema.load(parsed), and fails because theDummySessionis returned instead of the sqlalchemy scoped session.I am relying on
init_app()to bind the sqlalchemy session. I can see from other issues that people have suggested passingsqla_sessioninMeta, but I'd rather not copy and paste boilerplate if I can avoid it. Looking at the relevant line in marshmallow-sqlalchemy, it looks likeModelSchema.loadexpectsself._sessionto be set, whichModelSchema.OPTIONS_CLASS.sessiondoesn't do, but the setter does.The tests still pass, but as a new user of this ecosystem, I'd be happy to know if I've missed something. In particular, I know a lot of people use this stuff, so I'm not sure how it works for others.