<div dir="ltr">Hello, Hari!<div><br></div><div>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.<br>

<br>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.<br><br>

<br></div><div>You can wrap WSGI application with db_session buy writing single line of code:<br></div><div><br></div><div><br></div><div>� � from pony.orm import db_session</div><div>� � from flask import Flask</div><div>

<br></div><div>� � app = Flask(__name__)<br></div><div>� ��<span class="" style="font-size:13px;font-family:arial,sans-serif">app</span><span style="font-size:13px;font-family:arial,sans-serif">.</span><span class="" style="font-size:13px;font-family:arial,sans-serif">wsgi_app</span><span style="font-size:13px;font-family:arial,sans-serif">�= db_session(</span><span class="" style="font-size:13px;font-family:arial,sans-serif">app</span><span style="font-size:13px;font-family:arial,sans-serif">.</span><span class="" style="font-size:13px;font-family:arial,sans-serif">wsgi_app</span><span style="font-size:13px;font-family:arial,sans-serif">) �# add this line to wrap entire WSGI-application with db_session</span><br>

</div><div><br><br></div><div>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).</div><div><br></div><div>
I hope that this way all should work as expected. Please let me know if it works for you.</div>
<div><br></div><div><br>Best regards,</div><div>Alexander Kozlovsky</div><div><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 16, 2013 at 10:56 PM, Hari Rothstein <span dir="ltr"><<a href="mailto:harirothstein@gmail.com" target="_blank">harirothstein@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hey<br><br>I'm using flask, and I was using an old version of pony orm that uses the with_transaction decorator.<br>

<br>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.<br>


<br></div>Whats the best way to fix this?� Has anyone else run into the problem?<br></div>
<br>_______________________________________________<br>
ponyorm-list mailing list<br>
<a href="mailto:ponyorm-list@ponyorm.org">ponyorm-list@ponyorm.org</a><br>
<a href="/ponyorm-list" target="_blank">/ponyorm-list</a><br>
<br></blockquote></div><br></div></div>