[PonyORM-list] updated to new pony orm and broke apps login manager

Alexander Kozlovsky alexander.kozlovsky at gmail.com
Mon Sep 16 22:42:22 UTC 2013


Hello, Hari!

It seems that you decorated each individual view function with @db_session
decorator. This approach will work in simple cases, but not with plugins
like flask-login. The problem, as your correctly pointed, is that the
load_user() function, which should retrieve user user object by its id, is
called outside of view function, and hence, outside of db_session.

To solve this problem, you should wrap with db_session not individual view
functions, but entire WSGI application. Then the load_user() function will
be called inside db_session and all should work as expected.


You can wrap WSGI application with db_session buy writing single line of
code:


    from pony.orm import db_session
    from flask import Flask

    app = Flask(__name__)
    app.wsgi_app = db_session(app.wsgi_app)  # add this line to wrap entire
WSGI-application with db_session


Then you can remove @db_session decorator from you view functions, or leave
it as is (this decorator will do nothing because nested using of db_session
is ignored).

I hope that this way all should work as expected. Please let me know if it
works for you.


Best regards,
Alexander Kozlovsky



On Mon, Sep 16, 2013 at 10:56 PM, Hari Rothstein <harirothstein at gmail.com>wrote:

> Hey
>
> I'm using flask, and I was using an old version of pony orm that uses the
> with_transaction decorator.
>
> I updated to the new version, and fixed the decorators in my app, but
> there still seems to be some issues.  I am using flask-login to manage my
> user logins, and it seems to load the user outside of the view or something
> like that.
>
> Whats the best way to fix this?  Has anyone else run into the problem?
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20130917/cb9cd2b2/attachment.html>


More information about the ponyorm-list mailing list