-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ModelSchema.session setter rather than OPTIONS_CLASS #111
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 theDummySession
is 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_session
inMeta
, 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.load
expectsself._session
to be set, whichModelSchema.OPTIONS_CLASS.session
doesn'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.